Skip to content

Commit 2220f14

Browse files
committed
changed to new replay protection function, removed unused address primitive
1 parent e20750b commit 2220f14

11 files changed

Lines changed: 17 additions & 86 deletions

File tree

Assets/SequenceSDK/EcosystemWallet/IntegrationTests/AddressTests.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

Assets/SequenceSDK/EcosystemWallet/IntegrationTests/AddressTests.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

Assets/SequenceSDK/EcosystemWallet/IntegrationTests/Server/Server.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ internal class Server
3131
["signature_encode"] = async (parameters) => await new SignatureTests().SignatureEncode(parameters),
3232
["signature_concat"] = async (parameters) => await new SignatureTests().SignatureConcat(parameters),
3333
["signature_decode"] = async (parameters) => await new SignatureTests().SignatureDecode(parameters),
34-
// ADDRESS
35-
["address_calculate"] = async (parameters) => await new AddressTests().Calculate(parameters),
3634
// SESSION
3735
["session_empty"] = async (parameters) => await new SessionsTest().SessionEmpty(parameters),
3836
["session_encodeTopology"] = async (parameters) => await new SessionsTest().SessionEncodeTopology(parameters),

Assets/SequenceSDK/EcosystemWallet/UnitTests/SessionsUnitTests.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,5 @@ public void CreateSessionImageHash(string inputJson)
102102

103103
Debug.Log($"{imageHash}");
104104
}
105-
106-
[TestCase("0x8fee11e98795484615dcd9b86a9fbc2b62285931385baea72111101518d92dce", "0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f", "0x2e234DAe75C793f67A35089C9d99245E1C58470b", null)]
107-
public void CreateAddress(string imageHash, string factory, string module, string creationCode)
108-
{
109-
var address = AddressFactory.Create(imageHash.HexStringToByteArray(), factory, module, creationCode);
110-
Debug.Log($"Sequence Address: {address}");
111-
}
112105
}
113106
}

Packages/Sequence-Unity/Sequence/SequenceSDK/EcosystemWallet/Primitives/Address.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

Packages/Sequence-Unity/Sequence/SequenceSDK/EcosystemWallet/Primitives/Address/AddressFactory.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

Packages/Sequence-Unity/Sequence/SequenceSDK/EcosystemWallet/Primitives/Address/AddressFactory.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

Packages/Sequence-Unity/Sequence/SequenceSDK/EcosystemWallet/Primitives/Payload/Calls.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ public byte[] Encode(Address self = null)
120120
return encoder.Encode();
121121
}
122122

123+
public byte[] Hash(Address wallet, BigInteger chainId)
124+
{
125+
var typedData = new TypedDataToSign(wallet, chainId, new Parented(Array.Empty<Address>(), this));
126+
return typedData.GetSignPayload();
127+
}
128+
123129
public static Calls Decode(byte[] packed, Address self = null)
124130
{
125131
CallsDecoder decoder = new CallsDecoder(packed);

Packages/Sequence-Unity/Sequence/SequenceSDK/EcosystemWallet/Wallet/SessionSigner.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,21 @@ public async Task<bool> IsSupportedCall(Call call, Chain chain, SessionsTopology
108108
return (permissionIndex, sessionPermissions.permissions[permissionIndex]);
109109
}
110110

111-
public SessionCallSignature SignCall(Chain chain, Call call, int callIdx, SessionsTopology topology, BigInteger space, BigInteger nonce)
111+
public SessionCallSignature SignCall(Chain chain, Calls payload, int callIdx, SessionsTopology topology, BigInteger space, BigInteger nonce)
112112
{
113113
var pvKey = _credentials.privateKey;
114114
var eoaWallet = new EOAWallet(pvKey);
115115

116-
var hashedCall = HashCallWithReplayProtection(chain, call, callIdx, space, nonce);
116+
var hashedCall = HashCallWithReplayProtection(ParentAddress, chain, payload, callIdx, space, nonce);
117117
var signedCall = EthSignature.Sign(hashedCall, eoaWallet.privKey);
118118

119119
var rsy = RSY.UnpackFrom65(signedCall.HexStringToByteArray());
120120

121121
if (IsExplicit)
122122
{
123+
var call = payload.calls[callIdx];
123124
var permissionIndex = 0;
125+
124126
if (!CheckCallForIncrementUsageLimit(call))
125127
{
126128
permissionIndex = FindSupportedPermission(call, topology).Index;
@@ -175,15 +177,11 @@ private bool CheckCallForIncrementUsageLimit(Call call)
175177
ABI.ABI.FunctionSelector("incrementUsageLimit((bytes32,uint256)[])");
176178
}
177179

178-
private byte[] HashCallWithReplayProtection(Chain chain, Call call, BigInteger callIdx, BigInteger space, BigInteger nonce)
180+
private byte[] HashCallWithReplayProtection(Address wallet, Chain chain, Calls calls, BigInteger callIdx, BigInteger space, BigInteger nonce)
179181
{
180-
var chainBytes = BigInteger.Parse(chain.GetChainId()).ByteArrayFromNumber(32);
181-
var spaceBytes = space.ByteArrayFromNumber(32);
182-
var nonceBytes = nonce.ByteArrayFromNumber(32);
182+
var payloadHash = calls.Hash(wallet, chain.AsBigInteger());
183183
var callIdxBytes = callIdx.ByteArrayFromNumber(32);
184-
var callHashBytes = call.Hash().HexStringToByteArray();
185-
186-
var concatenated = ByteArrayExtensions.ConcatenateByteArrays(chainBytes, spaceBytes, nonceBytes, callIdxBytes, callHashBytes);
184+
var concatenated = ByteArrayExtensions.ConcatenateByteArrays(payloadHash, callIdxBytes);
187185
return SequenceCoder.KeccakHash(concatenated);
188186
}
189187

Packages/Sequence-Unity/Sequence/SequenceSDK/EcosystemWallet/Wallet/SignatureService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private async Task<SignatureOfSapientSignerLeaf> SignSapient(Chain chain, Envelo
6262
var signatures = new SessionCallSignature[_currentSigners.Length];
6363
for (var i = 0; i < _currentSigners.Length; i++)
6464
{
65-
var signature = _currentSigners[i].SignCall(chain, calls[i], i, _sessions, envelope.payload.space, envelope.payload.nonce);
65+
var signature = _currentSigners[i].SignCall(chain, envelope.payload, i, _sessions, envelope.payload.space, envelope.payload.nonce);
6666
signatures[i] = signature;
6767
}
6868

0 commit comments

Comments
 (0)