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

[Crypto Add] add secp256K1 Sign #3177

Merged
merged 8 commits into from
Mar 22, 2024
Merged

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Mar 8, 2024

Description

The issue is that the default C# dotnet does not support SECP256K1 curve on macos platform. We added support to SECP256K1 signature verify method for macos but did not add its sign method.

I found this issue when i was trying to run unit test here https://github.com/neo-project/neo-devpack-dotnet/blob/53a383ab5670d3c22d9761a113a50f7ef1a75ee0/tests/Neo.SmartContract.Framework.UnitTests/Services/CryptoTest.cs#L53

Fixes # (issue)

Test method Neo.SmartContract.Framework.UnitTests.Services.CryptoTest.Test_VerifySignatureWithMessage threw exception: 
System.PlatformNotSupportedException: The specified curve '1.3.132.0.10' or its parameters are not valid for this platform.
    at System.Security.Cryptography.EccSecurityTransforms.ImportParameters(ECParameters parameters)
   at System.Security.Cryptography.ECDsaImplementation.ECDsaSecurityTransforms.ImportParameters(ECParameters parameters)
   at System.Security.Cryptography.ECDsa.Create(ECParameters parameters)
   at Neo.SmartContract.Framework.UnitTests.Services.CryptoTest.Test_VerifySignatureWithMessage() in /Users/jinghuiliao/git/neo-devpack-dotnet/tests/Neo.SmartContract.Framework.UnitTests/Services/CryptoTest.cs:line 70
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • TestSecp256k1

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Jim8y
Copy link
Contributor Author

Jim8y commented Mar 8, 2024

Ok, macos, windows, ubuntu all have different behaviors,,,,,

@Jim8y Jim8y removed the Need Update label Mar 17, 2024
@Jim8y
Copy link
Contributor Author

Jim8y commented Mar 17, 2024

@shargon good to go now

@vang1ong7ang
Copy link
Contributor

btw how to ensure the IsOSX can be well tested?

shargon
shargon previously approved these changes Mar 19, 2024

var curve =
ecCurve == null || ecCurve == ECC.ECCurve.Secp256r1 ? ECCurve.NamedCurves.nistP256 :
ecCurve == ECC.ECCurve.Secp256k1 ? ECCurve.CreateFromFriendlyName("secP256k1") :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making the ECCurve.CreateFromFriendlyName("secP256k1") a public static property to allocate this object once, and then reuse it everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a cache system in another pr

src/Neo/Cryptography/Crypto.cs Outdated Show resolved Hide resolved
@shargon shargon merged commit a432e4b into neo-project:master Mar 22, 2024
5 of 6 checks passed
shargon added a commit that referenced this pull request Mar 22, 2024
@shargon shargon mentioned this pull request Mar 22, 2024
@Jim8y Jim8y deleted the secp256K1Sign branch March 22, 2024 15:49
shargon added a commit that referenced this pull request Mar 22, 2024
@roman-khimov roman-khimov added this to the v3.7.0 milestone May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants