Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/waas integration #28

Merged
merged 55 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
9dfdfbc
Fixed some namespaces and moved some of the class definitions into th…
BellringerQuinn Jul 12, 2023
65f0ae7
Extracted more classes into their own files.
BellringerQuinn Jul 12, 2023
8e0faa5
Rename class to match go-sequence
BellringerQuinn Jul 12, 2023
949859a
Added missing interface methods and a missing interface
BellringerQuinn Jul 12, 2023
58138fd
Made an Address datatype to make code more readable. Note that a stri…
BellringerQuinn Jul 12, 2023
b889bdf
No more implicit conversions from string to Address; you must now use…
BellringerQuinn Jul 12, 2023
5764968
Merge branch 'Refactor/addressAsObject' into Feature/sequenceIntegration
BellringerQuinn Jul 12, 2023
bb65a17
Use Address type instead of string in Sequence integration
BellringerQuinn Jul 12, 2023
499db4c
Created Sequence.Core.Signature namespace
BellringerQuinn Jul 12, 2023
1729bdb
Extract classes and interfaces from V2.cs into their own files, direc…
BellringerQuinn Jul 13, 2023
47bc865
Wallet configs as IImageHashables
BellringerQuinn Jul 13, 2023
81005f2
Added Hash datatype - a byte[] with a fixed length of 32. Digest.cs i…
BellringerQuinn Jul 13, 2023
8808ba2
Subdigest.cs implemented
BellringerQuinn Jul 14, 2023
f1a5bbb
Don't use Linq in Digest.cs
BellringerQuinn Jul 14, 2023
32a7d92
Updated ISignature and SignerSignature implementations
BellringerQuinn Jul 14, 2023
f22abc0
Merge remote-tracking branch 'origin/master' into Feature/sequenceInt…
BellringerQuinn Jul 14, 2023
4f63ca7
Moved Network.cs out of Wallet.cs. Removed Sequence.Core.Provider nam…
BellringerQuinn Jul 14, 2023
60115bf
Merge remote-tracking branch 'origin/master' into Feature/sequenceInt…
BellringerQuinn Jul 17, 2023
2b1d342
Fix some data types
BellringerQuinn Jul 18, 2023
836388b
RegularSignature.cs implementation. Added ToByteArray extension metho…
BellringerQuinn Jul 18, 2023
3242222
Moved extensions tests to a nested folder.
BellringerQuinn Jul 18, 2023
f2ed942
NoChainIDSignature.cs implementation
BellringerQuinn Jul 19, 2023
560e494
Added base datatypes
BellringerQuinn Jul 19, 2023
3a2dafe
Added remaining data types
BellringerQuinn Jul 19, 2023
c881502
Merge remote-tracking branch 'origin/master' into Feature/WaaSIntegra…
BellringerQuinn Aug 2, 2023
62e6a4c
Added IWallet interface
BellringerQuinn Aug 2, 2023
03433e4
Added an adapter between the IWallet defined in SequenceEthereum and …
BellringerQuinn Aug 2, 2023
7724479
Removed unneeded code, reducing network requests needed to send a con…
BellringerQuinn Aug 3, 2023
b386996
Fully removed code that had been commented out
BellringerQuinn Aug 3, 2023
e67a428
Added an additional method implementation to WaaSToWalletAdapter.cs a…
BellringerQuinn Aug 3, 2023
a6c8057
Allow inclusion of chain Id when signing messages
BellringerQuinn Aug 14, 2023
e0581e3
Sign messages as async method so that I could write the adapters for …
BellringerQuinn Aug 15, 2023
d325fd0
Added base WaaSWallet implementation - still requires constructor, bu…
BellringerQuinn Aug 15, 2023
2b3305b
Create WaaSWallet using JWT
BellringerQuinn Aug 16, 2023
566aa05
Fixed namespaces for WaaS. Added URL for WaaS service. Added tests fo…
BellringerQuinn Aug 16, 2023
391f6d5
Don't require an httpclient to create a WaaSWallet - WaaSWallet can c…
BellringerQuinn Aug 16, 2023
0327ef0
Modify wallet interface such that signing transactions and sending ra…
BellringerQuinn Aug 16, 2023
8eb3c75
Finished WaaSToWalletAdapter implementation
BellringerQuinn Aug 16, 2023
10ff040
Added an end to end test for a basic transfer on the mumbai testnet. …
BellringerQuinn Aug 17, 2023
77fe1bd
Added another convenience method to TransferEth to make it easier to …
BellringerQuinn Aug 17, 2023
b779ac4
Create WaaSToWalletAdapter more cleanly
BellringerQuinn Aug 17, 2023
ad72d97
IWallet support for SendTransactionBatch and SendTransactionBatchAndW…
BellringerQuinn Aug 17, 2023
2cd3a7c
Better signature and verification interface
BellringerQuinn Aug 17, 2023
f2a446e
Test waas signing message and checking valid signature. Fixed impleme…
BellringerQuinn Aug 17, 2023
cdf2c1c
Additional signature tests
BellringerQuinn Aug 18, 2023
2f6408d
Added test for contract interactions and deployment
BellringerQuinn Aug 21, 2023
7ae7cde
Don't include nonce when sending WaaS transactions as Marcin recommended
BellringerQuinn Aug 21, 2023
c5f59e0
Use 0x0000000000000000000000000000000000000000 as the zero address fo…
BellringerQuinn Aug 22, 2023
eb524e5
Merge remote-tracking branch 'origin/master' into Feature/WaaSIntegra…
BellringerQuinn Sep 7, 2023
867ecab
Added additional debug.log
BellringerQuinn Sep 7, 2023
214e7d4
Merge remote-tracking branch 'origin/master' into Feature/WaaSIntegra…
BellringerQuinn Nov 9, 2023
f4a6671
Remove extra semicolon
BellringerQuinn Dec 18, 2023
d8c4a7f
Create SignMessageArgs with Chain
BellringerQuinn Dec 18, 2023
16f485f
Create Transaction with Chain
BellringerQuinn Dec 18, 2023
7a16823
Rename vairable in constructor to make it more reader friendly
BellringerQuinn Dec 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Assets/SequenceSDK/Core/Hash.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
11 changes: 11 additions & 0 deletions Assets/SequenceSDK/Core/Hash.cs.meta

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

25 changes: 25 additions & 0 deletions Assets/SequenceSDK/Core/Network.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
11 changes: 11 additions & 0 deletions Assets/SequenceSDK/Core/Network.cs.meta

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

16 changes: 8 additions & 8 deletions Assets/SequenceSDK/Core/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Sequence.Provider;
using UnityEngine;

namespace Sequence.Core.Provider
namespace Sequence.Core
{
public struct ProviderOption
{
Expand All @@ -22,7 +22,7 @@ public class RPCProvider
{
// Logger logger;
string nodeURL;
HttpRpcClient httpClient;
IEthClient client;


public RPCProvider(string _nodeURL)
Expand All @@ -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<BigInteger> ChainID()
{
//?
await httpClient.SendRequest(payload);
string chainId = await client.ChainID();
return BigInteger.Parse(chainId);
}

}
Expand Down
20 changes: 20 additions & 0 deletions Assets/SequenceSDK/Core/Relayer.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
11 changes: 11 additions & 0 deletions Assets/SequenceSDK/Core/Relayer.cs.meta

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

47 changes: 32 additions & 15 deletions Assets/SequenceSDK/Core/Signature/Digest.cs
Original file line number Diff line number Diff line change
@@ -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; }

Expand All @@ -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)
{
Expand All @@ -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]
};
}


}
}
15 changes: 7 additions & 8 deletions Assets/SequenceSDK/Core/Signature/IImageHashable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
15 changes: 9 additions & 6 deletions Assets/SequenceSDK/Core/Signature/ISignature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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> signerSignatures);
params SignerSignatures[] signerSignatures);

// Recover a signature but only using the subdigest
(IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context,
Subdigest subdigest,
RPCProvider provider,
List<SignerSignatures> signerSignatures);
params SignerSignatures[] signerSignatures);

// Reduce returns an equivalent optimized signature.
ISignature Reduce(Subdigest subdigest);
Expand Down
20 changes: 20 additions & 0 deletions Assets/SequenceSDK/Core/Signature/SignatureType.cs
Original file line number Diff line number Diff line change
@@ -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 };
}
}
}
11 changes: 11 additions & 0 deletions Assets/SequenceSDK/Core/Signature/SignatureType.cs.meta

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

Loading