diff --git a/Assets/SequenceSDK/Core/Hash.cs b/Assets/SequenceSDK/Core/Hash.cs new file mode 100644 index 00000000..07471d45 --- /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; + public byte[] Bytes { get; private set; } + + public Hash() + { + Bytes = new byte[HashLength]; + } + + public Hash(byte[] b) + { + int length = Mathf.Min(HashLength, b.Length); + Bytes = new byte[HashLength]; + for (int i = 0; i < length; i++) + { + Bytes[i] = b[i]; + } + } + + public static implicit operator byte[](Hash hash) + { + return hash.Bytes; + } + + public static implicit operator string(Hash hash) + { + return hash.ToString(); + } + + public override string ToString() + { + return Bytes.ByteArrayToHexStringWithPrefix(); + } + } +} 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/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..e22f577d 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 { @@ -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 new file mode 100644 index 00000000..ff14991d --- /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) 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/Digest.cs b/Assets/SequenceSDK/Core/Signature/Digest.cs index 94f84797..602409ef 100644 --- a/Assets/SequenceSDK/Core/Signature/Digest.cs +++ b/Assets/SequenceSDK/Core/Signature/Digest.cs @@ -1,14 +1,16 @@ -using System; -using System.Linq; -using System.Numerics; +using System; +using System.Collections.Generic; +using System.Numerics; using System.Text; using Sequence.ABI; +using Sequence.Extensions; +using Sequence.Utils; 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,13 +19,30 @@ 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.ByteArrayToHexStringWithPrefix()} 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) + public Subdigest Subdigest(Address wallet, params BigInteger[] chainID) { if (chainID.Length == 0 || chainID[0] == null) { @@ -38,22 +57,20 @@ 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(this.Hash) - .ToArray(); + byte[] data = ByteArrayExtensions.ConcatenateByteArrays( + new byte[] { 0x19, 0x01 }, + chainIDBytes, + wallet.Value.ToByteArray(), + Hash); return new Subdigest { - Hash = SequenceCoder.ByteArrayToHexString(SequenceCoder.KeccakHash(data)), + Hash = new Hash(SequenceCoder.KeccakHash(data)), Digest = this, - WalletAddress = walletAddress, + WalletAddress = new Address(wallet), 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 ac048b12..1c390329 100644 --- a/Assets/SequenceSDK/Core/Signature/IImageHashable.cs +++ b/Assets/SequenceSDK/Core/Signature/IImageHashable.cs @@ -19,19 +19,18 @@ 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 - //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 Hash Hash { get; set; } - public static string imageHashApprovalSalt = SequenceCoder.KeccakHash("SetImageHash(bytes32 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() { - 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/Core/Signature/ISignature.cs b/Assets/SequenceSDK/Core/Signature/ISignature.cs index 743cc446..6fcb5185 100644 --- a/Assets/SequenceSDK/Core/Signature/ISignature.cs +++ b/Assets/SequenceSDK/Core/Signature/ISignature.cs @@ -3,35 +3,38 @@ using System.Numerics; using UnityEngine; using Sequence.Core.Wallet; -using Sequence.Core.Provider; +using Sequence.Core; +using System; +using System.Threading.Tasks; +using Sequence.Core.V2; 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(); + 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, 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/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/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 diff --git a/Assets/SequenceSDK/Core/Signature/Subdigest.cs b/Assets/SequenceSDK/Core/Signature/Subdigest.cs index 343e6e4d..cb96f1f7 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/Core/V2/ISignatureTree.cs b/Assets/SequenceSDK/Core/V2/ISignatureTree.cs index 715898f4..d9d5344a 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; @@ -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 168062cf..04e0e19d 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs @@ -5,13 +5,14 @@ using System.Numerics; using Sequence.Core.Signature; using Sequence.Core.Wallet; -using Sequence.Core.Provider; +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,12 +27,12 @@ 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, 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(); } @@ -41,7 +42,7 @@ public ISignature Reduce(Subdigest subdigest) throw new NotImplementedException(); } - public int 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 e04ab228..09a97435 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs @@ -5,45 +5,74 @@ using System.Numerics; using Sequence.Core.Signature; using Sequence.Core.Wallet; -using Sequence.Core.Provider; +using Sequence.Extensions; +using System.Threading.Tasks; +using Sequence.Core.V2.Wallet; namespace Sequence.Core.V2.Signature { public class NoChainIDSignature : ISignature { - public BigInteger Checkpoint() + 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 (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) { - throw new NotImplementedException(); + return RecoverSubdigest(context, digest.Subdigest(wallet), 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[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 int Threshold() + 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 e9e3e9a9..8f9ce2b8 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs @@ -5,48 +5,92 @@ using System.Numerics; using Sequence.Core.Signature; using Sequence.Core.Wallet; -using Sequence.Core.Provider; +using Sequence.Core; +using System.Threading.Tasks; +using Sequence.Core.V2.Wallet; +using Sequence.Extensions; 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 RegularSignature(bool isRegular, UInt16 threshold, UInt32 checkpoint, ISignatureTree tree) { - throw new NotImplementedException(); + this.IsRegular = isRegular; + this.threshold = threshold; + this.checkpoint = checkpoint; + this.Tree = tree; + } + + public UInt32 Checkpoint() + { + return checkpoint; } public byte[] Data() { - throw new NotImplementedException(); + byte[] data = new byte[0]; + if (this.IsRegular) + { + data = SignatureType.Regular.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(); + RegularSignature other = SignatureJoinParameterValidator.ValidateParameters(this, otherSignature); + + ISignatureTree tree = this.Tree.Join(other.Tree); + + return new RegularSignature(this.IsRegular, this.threshold, this.checkpoint, tree); } - 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, params SignerSignatures[] 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) + 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 RegularSignature(this.IsRegular, this.threshold, this.checkpoint, this.Tree.Reduce()); } - public int Threshold() + public UInt16 Threshold() { - throw new NotImplementedException(); + return threshold; } } } \ No newline at end of file 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: diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs index 0f77bba5..b85e9210 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; @@ -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 1e8f50ed..dbec103f 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; @@ -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 ac3d9d28..a6a5d4ac 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Numerics; -using Sequence.Core.Provider; using Sequence.Core.Signature; using Sequence.Core.Wallet; @@ -20,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 077e53a0..60e3e31c 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; @@ -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 73efda0a..c3b95217 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; @@ -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 a8713634..e5e38065 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; @@ -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 9320f1cd..f6aedb90 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; @@ -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 c0be4dc0..9504bdd3 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; @@ -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/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..ec038599 100644 --- a/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs +++ b/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Numerics; @@ -9,12 +9,19 @@ namespace Sequence.Core.V2.Wallet { [System.Serializable] - public class WalletConfig : IWalletConfig + public class WalletConfig : IWalletConfig, IImageHashable { public UInt16 threshold; 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/Core/Wallet/Wallet.cs b/Assets/SequenceSDK/Core/Wallet/Wallet.cs index d1276322..31ca6000 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; 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 57b99cdd..ea8e5bb8 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,9 +20,40 @@ 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); - 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(); + string address = hashedString.Substring(hashedString.Length - 40, 40).EnsureHexPrefix(); + Debug.Log($"Deployer {senderAddress}, nonce {nonce} - deployed to {address}"); + return address; + } + } + + 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/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/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/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(); 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/ContractIntegrationTests.cs b/Assets/SequenceSDK/Ethereum/Tests/ContractIntegrationTests.cs index 6a8c82f5..6ca6eb68 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/ContractIntegrationTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/ContractIntegrationTests.cs @@ -32,8 +32,8 @@ public async Task _TestDeployComplexContract() { try { - TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet1, complexContractBytecode); - complexContractAddress = receipt.contractAddress; + ContractDeploymentResult receipt = await ContractDeployer.Deploy(client, wallet1, complexContractBytecode); + complexContractAddress = receipt.Receipt.contractAddress; Assert.IsNotEmpty(complexContractAddress); } catch (Exception ex) 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/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/ExtensionsTests/BoolExtensionsTests.cs b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/BoolExtensionsTests.cs new file mode 100644 index 00000000..746e3c03 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/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/ExtensionsTests/BoolExtensionsTests.cs.meta b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/BoolExtensionsTests.cs.meta new file mode 100644 index 00000000..fa651419 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/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/ExtensionsTests/ByteArrayExtensionsTests.cs b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/ByteArrayExtensionsTests.cs new file mode 100644 index 00000000..519c1c1d --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/ByteArrayExtensionsTests.cs @@ -0,0 +1,33 @@ +using System.Collections; +using System.Collections.Generic; +using NUnit.Framework; +using UnityEngine; +using Sequence.Extensions; +using Sequence.Utils; + +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/ExtensionsTests/ByteArrayExtensionsTests.cs.meta b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/ByteArrayExtensionsTests.cs.meta new file mode 100644 index 00000000..690534b0 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/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/ExtensionsTests/UInt16ExtensionsTests.cs b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/UInt16ExtensionsTests.cs new file mode 100644 index 00000000..c2b309a1 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/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/ExtensionsTests/UInt16ExtensionsTests.cs.meta b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/UInt16ExtensionsTests.cs.meta new file mode 100644 index 00000000..e150d85a --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/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/ExtensionsTests/UInt32ExtensionsTests.cs b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/UInt32ExtensionsTests.cs new file mode 100644 index 00000000..f317f729 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/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/ExtensionsTests/UInt32ExtensionsTests.cs.meta b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/UInt32ExtensionsTests.cs.meta new file mode 100644 index 00000000..38603306 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/UInt32ExtensionsTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 25e0f4380aaa143639ac01d8f6e0e335 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: 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 78b4437e..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"; @@ -412,7 +413,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" } }, diff --git a/Assets/SequenceSDK/Ethereum/Tests/SequenceTests.asmdef b/Assets/SequenceSDK/Ethereum/Tests/SequenceTests.asmdef index 2b5c599e..71d5b377 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/SequenceTests.asmdef +++ b/Assets/SequenceSDK/Ethereum/Tests/SequenceTests.asmdef @@ -5,6 +5,7 @@ "GUID:27619889b8ba8c24980f49ee34dbb44a", "GUID:0acc523941302664db1f4e527237feb3", "GUID:f7fd4ba36aabd1d499450c174865e70b", + "GUID:4e0a798abbda240658187632ae443a67", "GUID:f78a27d6a73d94c4baf04337e0add4dc" ], "includePlatforms": [ diff --git a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs index 312028d5..9c23240c 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,14 +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); - string tx = transaction.SignAndEncodeTransaction(wallet); - string result = await wallet.SendRawTransaction(client, tx); + 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); } @@ -128,16 +134,19 @@ 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); + 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) + catch (Exception ex) { Assert.Fail("Expected no exception, but got: " + ex.Message); } @@ -152,9 +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, gasPrice_ERC20Mock, gasLimit_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) @@ -169,7 +181,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) @@ -190,25 +202,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); } @@ -217,26 +234,52 @@ public void TestWalletRandom() { EthWallet wallet = new EthWallet(); Assert.NotNull(wallet); - + } [Test] - public void TestWalletSignMessage() + public async Task TestWalletSignMessage() { EthWallet wallet = new EthWallet(); 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"); + Assert.IsTrue(valid); + } + + private static IEnumerable iWalletTestCases() + { + var adapter = WaaSToWalletAdapter.CreateAsync(new WaaSWallet( + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX2lkIjoyLCJ3YWxsZXQiOiIweDY2MDI1MDczNGYzMTY0NDY4MWFlMzJkMDViZDdlOGUyOWZlYTI5ZTEifQ.FC8WmaC_hW4svdrs4rxyKcvoekfVYFkFFvGwUOXzcHA")).Result; + 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, string message) + { + string address = wallet.GetAddress(); + Assert.NotNull(address); + + string sig = await wallet.SignMessage(message, "0x89"); Assert.NotNull(sig); - bool valid = wallet.IsValidSignature(sig, "hi"); + bool valid = await wallet.IsValidSignature(sig, message, chainId: "0x89"); Assert.IsTrue(valid); } [Test] - public void TestWalletSignMessageExistingPrefix() + public async Task TestWalletSignMessageExistingPrefix() { EthWallet wallet = new EthWallet("b3c503217dbb0fae8950dadf73e2f500e968abddb95e22306ba95bbc7301cc01"); CollectionAssert.AreEqual(SequenceCoder.HexStringToByteArray("b3c503217dbb0fae8950dadf73e2f500e968abddb95e22306ba95bbc7301cc01"), wallet.privKey.sec.ToBytes()); @@ -247,13 +290,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"); @@ -265,14 +308,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()); @@ -283,13 +326,49 @@ 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); 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 58c011de..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; @@ -12,13 +14,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; } @@ -132,7 +134,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(); @@ -143,5 +145,10 @@ public string SignAndEncodeTransaction(IWallet wallet) string tx = this.RLPEncode(); return tx; } + + public void IncrementNonceBy(int i) + { + this.Nonce += i; + } } } 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/Ethereum/Utils/BoolExtensions.cs b/Assets/SequenceSDK/Ethereum/Utils/BoolExtensions.cs new file mode 100644 index 00000000..6d6db4c2 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Utils/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/Utils/BoolExtensions.cs.meta b/Assets/SequenceSDK/Ethereum/Utils/BoolExtensions.cs.meta new file mode 100644 index 00000000..fdf4258f --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Utils/BoolExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3242cd477cc0849e8891bb359b362cfc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Ethereum/Utils/ByteArrayExtensions.cs b/Assets/SequenceSDK/Ethereum/Utils/ByteArrayExtensions.cs index 8a4f331c..1b5a717a 100644 --- a/Assets/SequenceSDK/Ethereum/Utils/ByteArrayExtensions.cs +++ b/Assets/SequenceSDK/Ethereum/Utils/ByteArrayExtensions.cs @@ -1,7 +1,7 @@ using System; using Sequence.ABI; -namespace Sequence.Utils +namespace Sequence.Extensions { public static class ByteArrayExtensions { diff --git a/Assets/SequenceSDK/Ethereum/Utils/ByteArrayExtensions.cs.meta b/Assets/SequenceSDK/Ethereum/Utils/ByteArrayExtensions.cs.meta index 523fdf95..cba5e42a 100644 --- a/Assets/SequenceSDK/Ethereum/Utils/ByteArrayExtensions.cs.meta +++ b/Assets/SequenceSDK/Ethereum/Utils/ByteArrayExtensions.cs.meta @@ -1,3 +1,11 @@ fileFormatVersion: 2 -guid: f12b4e05183b45e9bcffe6f144ac488b -timeCreated: 1692103469 \ No newline at end of file +guid: badbc0f0a07dd4f4cbf58499e2e8ea5a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs b/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs index 4fbc462c..46025a72 100644 --- a/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs +++ b/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs @@ -1,6 +1,6 @@ using System; -namespace Sequence.Utils +namespace Sequence.Ethereum.Utils { public static class GenericHelpers { @@ -26,7 +26,7 @@ public static T[] Take(this T[] source, int count) return result; } - + public static bool SequenceEqual(this T[] first, T[] second) { if (first == null) diff --git a/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs.meta b/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs.meta index e8e53052..9fff706d 100644 --- a/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs.meta +++ b/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs.meta @@ -1,3 +1,3 @@ fileFormatVersion: 2 -guid: cbf949cbf7dc4a0a955c65e5cb9a361d -timeCreated: 1692103100 \ No newline at end of file +guid: 3c1bdca7130945a59686db2b340e47eb +timeCreated: 1691067840 \ No newline at end of file diff --git a/Assets/SequenceSDK/Ethereum/Utils/UInt16Extensions.cs b/Assets/SequenceSDK/Ethereum/Utils/UInt16Extensions.cs new file mode 100644 index 00000000..a4db70c9 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Utils/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/Utils/UInt16Extensions.cs.meta b/Assets/SequenceSDK/Ethereum/Utils/UInt16Extensions.cs.meta new file mode 100644 index 00000000..5b6b646d --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Utils/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/Utils/UInt32Extensions.cs b/Assets/SequenceSDK/Ethereum/Utils/UInt32Extensions.cs new file mode 100644 index 00000000..4ef70ca6 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Utils/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/Utils/UInt32Extensions.cs.meta b/Assets/SequenceSDK/Ethereum/Utils/UInt32Extensions.cs.meta new file mode 100644 index 00000000..26554105 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Utils/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/Wallet/EthWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs index e8fc736e..d1047b19 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs @@ -10,7 +10,10 @@ using System; using System.Numerics; using System.Threading.Tasks; +using Sequence.Extensions; +using Sequence.Transactions; using Sequence.Utils; +using UnityEngine; namespace Sequence.Wallet { @@ -52,11 +55,16 @@ private string GenerateAddress() Array.Copy(publickeyBytes, 1, publicKeyBytes64, 0, 64); - return PubkeyToAddress(publicKeyBytes64); + return IWallet.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()); @@ -75,25 +83,62 @@ 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 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(); 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 @@ -109,8 +154,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 async Task 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); } @@ -121,10 +170,15 @@ public string SignMessage(byte[] message) /// /// The message to sign as a string. /// The signature as a string. - public string SignMessage(string message) + public Task 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); } /// @@ -133,7 +187,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))); @@ -163,15 +217,20 @@ 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, string chainId = "", uint accountIndex = 0) { - 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 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); } @@ -179,29 +238,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. /// @@ -212,19 +248,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 e9894e5e..fe9e0a97 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs @@ -1,23 +1,29 @@ +using System; using System.Collections; using System.Collections.Generic; using System.Numerics; using System.Text; using System.Threading.Tasks; +using NBitcoin.Secp256k1; using Sequence.ABI; +using Sequence.Extensions; using Sequence.Provider; -using Sequence.Utils; +using Sequence.Signer; +using Sequence.Transactions; +using Sequence.Ethereum.Utils; using UnityEngine; namespace Sequence.Wallet { public interface IWallet { - 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); - public Task SendRawTransaction(IEthClient client, string signedTransactionData); - public Task SendRawTransactionAndWaitForReceipt(IEthClient client, string signedTransactionData); + 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); /// /// @@ -34,22 +40,26 @@ public interface IWallet /// /// The message to sign as a byte array. /// The signature as a string. - public string SignMessage(byte[] message); + 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); + public Task SignMessage(string message, string chainId = null); /// /// Verifies the validity of a signature for a given message. /// /// 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, string chainId = "", uint accountIndex = 0); + + /// /// Recovers the Ethereum address from a message and its signature. @@ -57,8 +67,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. @@ -72,7 +111,7 @@ public static byte[] PrefixedMessage(byte[] message) byte[] messageLen = Encoding.UTF8.GetBytes((message.Length).ToString()); if (!message.Take(message191.Length).SequenceEqual(message191)) { - message = ByteArrayExtensions.ConcatenateByteArrays(message191 , messageLen, message); + message = ByteArrayExtensions.ConcatenateByteArrays(message191, messageLen, message); } return message; diff --git a/Assets/SequenceSDK/Ethereum/Wallet/TransactionSender.cs b/Assets/SequenceSDK/Ethereum/Wallet/TransactionSender.cs index 546d8876..53ab555f 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/TransactionSender.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/TransactionSender.cs @@ -12,12 +12,12 @@ 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); - string result = await fromWallet.SendRawTransaction(client, tx); + string result = await fromWallet.SendTransaction(client, transaction); return result; } 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..ee27b7ed --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/Page.cs @@ -0,0 +1,28 @@ + + +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; } + 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) + { + 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/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..ad86c252 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs @@ -0,0 +1,19 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class IsValidMessageSignatureArgs + { + public uint chainId; + public string walletAddress; + public string message; + public string signature; + + public IsValidMessageSignatureArgs(uint 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..7692b08e --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs @@ -0,0 +1,26 @@ +using UnityEngine.Serialization; + +namespace Sequence.WaaS +{ + [System.Serializable] + public class SignMessageArgs + { + public uint chainId; + public string walletAddress; + public string message; + + public SignMessageArgs(uint chainId, string walletAddress, string message) + { + this.chainId = chainId; + 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 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 new file mode 100644 index 00000000..3b0e6c7d --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/Partner.cs @@ -0,0 +1,23 @@ + + +namespace Sequence.WaaS +{ + [System.Serializable] + public class Partner + { + public uint id { get; private set; } + public string name; + public string jwtAlg { get; private set; } + 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/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.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/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..8a7d030e --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/GetWalletAddressReturn.cs @@ -0,0 +1,13 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + 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/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/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..c2171ce2 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Transactions; +using UnityEngine; +using UnityEngine.Serialization; +using StringExtensions = Sequence.Utils.StringExtensions; + +namespace Sequence.WaaS +{ + [System.Serializable] + public class Transaction + { + public static readonly string WaaSZeroAddress = "0x0000000000000000000000000000000000000000"; + public uint chainId; + [FormerlySerializedAs("from")] public string fromAddress; + [FormerlySerializedAs("to")] public string toAddress; + public string autoGas; + public BigInteger? nonce; + public string value; + public string calldata; + public string tokenAddress; + public string tokenAmount; + public string[] tokenIds; + public string[] tokenAmounts; + + 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.fromAddress = fromAddress; + if (toAddress == StringExtensions.ZeroAddress) + { + toAddress = WaaSZeroAddress; + } + this.toAddress = toAddress; + this.autoGas = autoGas; + this.nonce = nonce; + this.value = value; + this.calldata = calldata; + this.tokenAddress = tokenAddress; + this.tokenAmount = tokenAmount; + this.tokenIds = tokenIds; + this.tokenAmounts = tokenAmounts; + } + + 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.fromAddress = fromAddress; + if (toAddress == StringExtensions.ZeroAddress) + { + toAddress = WaaSZeroAddress; + } + this.toAddress = toAddress; + 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/HttpClient.cs b/Assets/SequenceSDK/WaaS/HttpClient.cs new file mode 100644 index 00000000..92cdc9b4 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/HttpClient.cs @@ -0,0 +1,90 @@ +using System; +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 Sequence.WaaS +{ + 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() + { + this._defaultHeaders = new Dictionary(); + } + + public void AddDefaultHeader(string key, string value) + { + this._defaultHeaders[key] = value; + } + + public async Task SendRequest(string path, T args, [CanBeNull] Dictionary headers = null) + { + string url = _url + "/" + path; + string requestJson = JsonConvert.SerializeObject(args, serializerSettings); + 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) + { + headers = _defaultHeaders; + } + + foreach (string key in headers.Keys) + { + 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) + { + await Task.Yield(); + } + + if (request.error != null || request.result != UnityWebRequest.Result.Success) + { + throw new Exception($"Error sending request to {url}: {request.error}"); + } + else + { + byte[] results = request.downloadHandler.data; + var responseJson = Encoding.UTF8.GetString(results); + T2 result = JsonConvert.DeserializeObject(responseJson); + request.Dispose(); + return result; + } + } + + private string ExtractHeaders(UnityWebRequest request) + { + StringBuilder headerBuilder = new StringBuilder(); + foreach (string headerKey in new string[]{"Content-Type", "Accept", "Authorization"}) + { + string headerValue = request.GetRequestHeader(headerKey); + headerBuilder.Append($"-H '{headerKey}: {headerValue}' "); + } + return headerBuilder.ToString(); + } + } +} \ 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/IWallet.cs b/Assets/SequenceSDK/WaaS/IWallet.cs new file mode 100644 index 00000000..f55a2106 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/IWallet.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Sequence.WaaS; + +namespace Sequence.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 diff --git a/Assets/SequenceSDK/WaaS/JwtHelper.cs b/Assets/SequenceSDK/WaaS/JwtHelper.cs new file mode 100644 index 00000000..d648225d --- /dev/null +++ b/Assets/SequenceSDK/WaaS/JwtHelper.cs @@ -0,0 +1,55 @@ +using System; +using System.Text; +using System.Web; +using Sequence; +using UnityEngine; + +namespace Sequence.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"); + } + + string payloadBase64 = PadToBase64(parts[1]); + byte[] payloadBytes = Convert.FromBase64String(payloadBase64); + string payloadJson = 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); + } + + 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/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/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: 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/EndToEndTests.cs b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs new file mode 100644 index 00000000..d371a5ab --- /dev/null +++ b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs @@ -0,0 +1,131 @@ +using System; +using System.Numerics; +using System.Threading.Tasks; +using NUnit.Framework; +using Sequence.Contracts; +using Sequence.Provider; +using Sequence.Transactions; +using UnityEngine; + +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 + { + [Test] + public async Task TestTransferOnTestnet() + { + 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); + + BigInteger startingBalance = await client.BalanceAt("0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f"); + BigInteger startingBalance2 = await client.BalanceAt(wallet.GetAddress().Value); + + TransactionReceipt receipt = await wallet.SendTransactionAndWaitForReceipt(client, transaction); + + BigInteger endingBalance = await client.BalanceAt("0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f"); + BigInteger endingBalance2 = await client.BalanceAt(wallet.GetAddress().Value); + + Debug.Log($"starting balance {startingBalance} ending balance {endingBalance}"); + Debug.Log($"starting balance 2 {startingBalance2} ending balance 2 {endingBalance2}"); + 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); + } + } + + [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 + { + ContractDeploymentResult result = await ContractDeployer.Deploy(client, wallet, ERC20Tests.bytecode); + TransactionReceipt receipt = result.Receipt; + string contractAddress = result.PreCalculatedContractAddress; + + 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 diff --git a/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs.meta b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs.meta new file mode 100644 index 00000000..1314dc65 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 016dcc772c614de8852a96c7598444b7 +timeCreated: 1692275296 \ 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 new file mode 100644 index 00000000..a000bd48 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs @@ -0,0 +1,119 @@ +using System.Collections.Generic; +using System.Numerics; +using System.Threading.Tasks; +using Sequence; +using Sequence.Provider; +using Sequence.WaaS; +using System; +using Sequence.ABI; +using Sequence.Extensions; +using Sequence.Transactions; +using Sequence.Utils; + +namespace Sequence.WaaS +{ + 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; + _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 async Task SendTransaction(IEthClient client, EthTransaction transaction) + { + 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; + } + + public async Task SendTransactionAndWaitForReceipt(IEthClient client, EthTransaction transaction) + { + string transactionHash = await SendTransaction(client, transaction); + TransactionReceipt receipt = await client.WaitForTransactionReceipt(transactionHash); + 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, null, 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) + { + string messageString = SequenceCoder.HexStringToHumanReadable(SequenceCoder.ByteArrayToHexString(message)); + string chainIdString = + SequenceCoder.HexStringToHumanReadable(SequenceCoder.ByteArrayToHexString(chainId)); + + return await SignMessage(messageString, chainIdString); + } + + public async Task SignMessage(string message, string 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((uint)chainId.HexStringToInt(), GetAddress(accountIndex), message, signature); + var result = await _wallet.IsValidMessageSignature(args); + return result.isValid; + } + } +} \ 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 diff --git a/Assets/SequenceSDK/WaaS/WaaSWallet.cs b/Assets/SequenceSDK/WaaS/WaaSWallet.cs new file mode 100644 index 00000000..4d4ef846 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/WaaSWallet.cs @@ -0,0 +1,104 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Sequence.WaaS +{ + public class WaaSWallet : IWallet + { + private HttpClient _httpClient; + private Address _address; + + public WaaSWallet(string jwt) + { + this._httpClient = new HttpClient(); + this._address = JwtHelper.GetWalletAddressFromJwt(jwt); + this._httpClient.AddDefaultHeader("Authorization", $"Bearer {jwt}"); + } + + public Task CreatePartner(CreatePartnerArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("CreatePartner", args, headers); + } + + public Task UpdatePartner(UpdatePartnerArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("UpdatePartner", args, headers); + } + + public Task CreatePartnerWalletConfig(CreatePartnerWalletConfigArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("CreatePartnerWalletConfig", args, headers); + } + + public Task PartnerWalletConfig(PartnerWalletConfigArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("PartnerWalletConfig", args, headers); + } + + public Task DeployPartnerParentWallet(DeployPartnerParentWalletArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("DeployPartnerParentWallet", args, headers); + } + + public Task AddPartnerWalletSigner(AddPartnerWalletSignerArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("AddPartnerWalletSigner", args, headers); + } + + public Task RemovePartnerWalletSigner(RemovePartnerWalletSignerArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("RemovePartnerWalletSigner", args, headers); + } + + public Task ListPartnerWalletSigners(ListPartnerWalletSignersArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("ListPartnerWalletSigners", args, headers); + } + + public Task PartnerWallets(PartnerWalletsArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("PartnerWallets", args, headers); + } + + public Task CreateWallet(CreateWalletArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("CreateWallet", args, headers); + } + + public Task GetWalletAddress(GetWalletAddressArgs args, Dictionary headers = null) + { + GetWalletAddressReturn result = new GetWalletAddressReturn(this._address.Value); + return Task.FromResult(result); + } + + public Task DeployWallet(DeployWalletArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("DeployWallet", args, headers); + } + + public Task Wallets(WalletsArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("Wallets", args, headers); + } + + public Task SignMessage(SignMessageArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("SignMessage", args, headers); + } + + public Task IsValidMessageSignature(IsValidMessageSignatureArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("IsValidMessageSignature", args, headers); + } + + public Task SendTransaction(SendTransactionArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("SendTransaction", args, headers); + } + + public Task SendTransactionBatch(SendTransactionBatchArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest("SendTransactionBatch", 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