Skip to content

Commit

Permalink
Adding Equals override to compare keys and accounts efficiently (#218)
Browse files Browse the repository at this point in the history
* Adding Equals override to compare keys and accounts efficiently

* Bumping version and fixing PrivateKey Equals
  • Loading branch information
hoakbuilds committed Oct 2, 2021
1 parent f1ba229 commit e397fb8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SharedBuildProperties.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Product>Solnet</Product>
<Version>0.4.9</Version>
<Version>0.4.10</Version>
<Copyright>Copyright 2021 &#169; Solnet</Copyright>
<Authors>blockmountain</Authors>
<PublisherName>blockmountain</PublisherName>
Expand Down
8 changes: 8 additions & 0 deletions src/Solnet.Wallet/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ private static byte[] GenerateRandomSeed()
return bytes;
}

/// <inheritdoc cref="Equals(object)"/>
public override bool Equals(object obj)
{
if (obj is Account account) return account.PublicKey == this.PublicKey;

return false;
}

/// <summary>
/// Conversion between a <see cref="Account"/> object and the corresponding private key.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Solnet.Wallet/PrivateKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ public byte[] Sign(byte[] message)
return signature;
}

/// <inheritdoc cref="Equals(object)"/>
public override bool Equals(object obj)
{
if (obj is PrivateKey pk) return pk.Key == this.Key;

return false;
}

/// <summary>
/// Conversion between a <see cref="PrivateKey"/> object and the corresponding base-58 encoded private key.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Solnet.Wallet/PublicKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public bool Verify(byte[] message, byte[] signature)
return Ed25519.Verify(signature, message, KeyBytes);
}

/// <inheritdoc cref="Equals(object)"/>
public override bool Equals(object obj)
{
if (obj is PublicKey pk) return pk.Key == this.Key;

return false;
}

/// <summary>
/// Conversion between a <see cref="PublicKey"/> object and the corresponding base-58 encoded public key.
/// </summary>
Expand Down

0 comments on commit e397fb8

Please sign in to comment.