-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add hardofork HF_Echidna * Add entries to `Designation` event (#3397) * Add entries to Designation event * Change to HF_Echidna * Add UT * Add count * [Neo Core StdLib] Add Base64url (#3453) * add base64url * active in * update placehold hf height * fix hf issue and move methods to proper place. * fix test * use identifymodel instead. * add hardofork HF_Echidna * Add entries to `Designation` event (#3397) * Add entries to Designation event * Change to HF_Echidna * Add UT * Add count * [Neo Core StdLib] Add Base64url (#3453) * add base64url * active in * update placehold hf height * fix hf issue and move methods to proper place. * fix test * use identifymodel instead. * add hardofork HF_Echidna * Add entries to `Designation` event (#3397) * Add entries to Designation event * Change to HF_Echidna * Add UT * Add count * [Neo Core StdLib] Add Base64url (#3453) * add base64url * active in * update placehold hf height * fix hf issue and move methods to proper place. * fix test * use identifymodel instead. * format * Fixed typo * Added back #3397 * Fixed tests * fixed global.json * Update src/Neo/Neo.csproj * Update src/Neo/Neo.csproj * [`Fix`]: integer overflow in `JumpTable.SubStr ` (#3496) * fix: int overflow in SubStr * fix: int overflow in SubStr * format * Versioning change * Clean * Rename * Show change * Space * remove duplicated lines in gitignroe --------- Co-authored-by: Jimmy <[email protected]> Co-authored-by: Shargon <[email protected]> * Fix NEO callstates (#3599) * Allow callstates to use HF * Rename to method * Other rename * Change the way * Reduce changes * Reduce changes * Adapt name always * Avoid string when only is lower the first char * UT * Test all * Update src/Neo/ProtocolSettings.cs Co-authored-by: Christopher Schuchardt <[email protected]> * Update src/Neo/ProtocolSettings.cs Co-authored-by: Christopher Schuchardt <[email protected]> * Reuse Load from stream * Unify * Fix default logic * Change ContractMethod to allowMultiple * Use LowerInvariant * Move CheckingHardfork * Remove optional arg * Fix build * Avoid file not found error --------- Co-authored-by: Christopher Schuchardt <[email protected]> * fix tests error (#3636) * fux build error * Update src/Neo/SmartContract/ApplicationEngine.cs --------- Co-authored-by: Shargon <[email protected]> * NeoToken: accept candidate registration via onNEP17Payment (#3597) Solves two problems: * inability to estimate GAS needed for registerCandidate in a regular way because of its very high fee (more than what normal RPC servers allow) * inability to have MaxBlockSystemFee lower than the registration price which is very high on its own (more than practically possible to execute) Fixes #3552. Signed-off-by: Roman Khimov <[email protected]> * specify the argument exception information. * Fix Ut (#3635) * NeoToken: add NEP-27 to supported standards list starting from Echidna (#3643) #3597 introduces `onNEP17Payment` handler to native NeoToke contract starting from Echidna hardfork. We need to update the list of supported standards respectively. Signed-off-by: Anna Shaleva <[email protected]> * ut: fix HF_Echidna unit tests (#3646) * Fix UT * Update src/Neo/ProtocolSettings.cs Co-authored-by: nan01ab <[email protected]> * Update src/Neo/ProtocolSettings.cs Co-authored-by: nan01ab <[email protected]> * Update src/Neo/ProtocolSettings.cs Co-authored-by: Christopher Schuchardt <[email protected]> --------- Co-authored-by: Jimmy <[email protected]> Co-authored-by: nan01ab <[email protected]> Co-authored-by: Christopher Schuchardt <[email protected]> * [Core Add] Add support to Ed25519 (#3507) * fix unnecessary change * Clean using --------- Co-authored-by: Fernando Diaz Toledano <[email protected]> * Fix `HF_Echidna` comments (#3679) * Fix obsolete * Fix https://github.com/neo-project/neo/pull/3454/files#r1912152270 * Fix comment * Update RoleManagement.cs * Unset HF_Echidna * Revert getTransaction * Revert verifyWithECDsa * format --------- Signed-off-by: Roman Khimov <[email protected]> Signed-off-by: Anna Shaleva <[email protected]> Co-authored-by: Shargon <[email protected]> Co-authored-by: Christopher Schuchardt <[email protected]> Co-authored-by: nan01ab <[email protected]> Co-authored-by: Roman Khimov <[email protected]> Co-authored-by: Anna Shaleva <[email protected]> Co-authored-by: Vitor Nazário Coelho <[email protected]>
- Loading branch information
1 parent
02fc4cb
commit befe7f6
Showing
35 changed files
with
948 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright (C) 2015-2025 The Neo Project. | ||
// | ||
// Ed25519.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Org.BouncyCastle.Crypto.Generators; | ||
using Org.BouncyCastle.Crypto.Parameters; | ||
using Org.BouncyCastle.Crypto.Signers; | ||
using Org.BouncyCastle.Security; | ||
using System; | ||
|
||
namespace Neo.Cryptography | ||
{ | ||
public class Ed25519 | ||
{ | ||
internal const int PublicKeySize = 32; | ||
private const int PrivateKeySize = 32; | ||
internal const int SignatureSize = 64; | ||
|
||
/// <summary> | ||
/// Generates a new Ed25519 key pair. | ||
/// </summary> | ||
/// <returns>A byte array containing the private key.</returns> | ||
public static byte[] GenerateKeyPair() | ||
{ | ||
var keyPairGenerator = new Ed25519KeyPairGenerator(); | ||
keyPairGenerator.Init(new Ed25519KeyGenerationParameters(new SecureRandom())); | ||
var keyPair = keyPairGenerator.GenerateKeyPair(); | ||
return ((Ed25519PrivateKeyParameters)keyPair.Private).GetEncoded(); | ||
} | ||
|
||
/// <summary> | ||
/// Derives the public key from a given private key. | ||
/// </summary> | ||
/// <param name="privateKey">The private key as a byte array.</param> | ||
/// <returns>The corresponding public key as a byte array.</returns> | ||
/// <exception cref="ArgumentException">Thrown when the private key size is invalid.</exception> | ||
public static byte[] GetPublicKey(byte[] privateKey) | ||
{ | ||
if (privateKey.Length != PrivateKeySize) | ||
throw new ArgumentException("Invalid private key size", nameof(privateKey)); | ||
|
||
var privateKeyParams = new Ed25519PrivateKeyParameters(privateKey, 0); | ||
return privateKeyParams.GeneratePublicKey().GetEncoded(); | ||
} | ||
|
||
/// <summary> | ||
/// Signs a message using the provided private key. | ||
/// Parameters are in the same order as the sample in the Ed25519 specification | ||
/// Ed25519.sign(privkey, pubkey, msg) with pubkey omitted | ||
/// ref. https://datatracker.ietf.org/doc/html/rfc8032. | ||
/// </summary> | ||
/// <param name="privateKey">The private key used for signing.</param> | ||
/// <param name="message">The message to be signed.</param> | ||
/// <returns>The signature as a byte array.</returns> | ||
/// <exception cref="ArgumentException">Thrown when the private key size is invalid.</exception> | ||
public static byte[] Sign(byte[] privateKey, byte[] message) | ||
{ | ||
if (privateKey.Length != PrivateKeySize) | ||
throw new ArgumentException("Invalid private key size", nameof(privateKey)); | ||
|
||
var signer = new Ed25519Signer(); | ||
signer.Init(true, new Ed25519PrivateKeyParameters(privateKey, 0)); | ||
signer.BlockUpdate(message, 0, message.Length); | ||
return signer.GenerateSignature(); | ||
} | ||
|
||
/// <summary> | ||
/// Verifies an Ed25519 signature for a given message using the provided public key. | ||
/// Parameters are in the same order as the sample in the Ed25519 specification | ||
/// Ed25519.verify(public, msg, signature) | ||
/// ref. https://datatracker.ietf.org/doc/html/rfc8032. | ||
/// </summary> | ||
/// <param name="publicKey">The 32-byte public key used for verification.</param> | ||
/// <param name="message">The message that was signed.</param> | ||
/// <param name="signature">The 64-byte signature to verify.</param> | ||
/// <returns>True if the signature is valid for the given message and public key; otherwise, false.</returns> | ||
/// <exception cref="ArgumentException">Thrown when the signature or public key size is invalid.</exception> | ||
public static bool Verify(byte[] publicKey, byte[] message, byte[] signature) | ||
{ | ||
if (signature.Length != SignatureSize) | ||
throw new ArgumentException("Invalid signature size", nameof(signature)); | ||
|
||
if (publicKey.Length != PublicKeySize) | ||
throw new ArgumentException("Invalid public key size", nameof(publicKey)); | ||
|
||
var verifier = new Ed25519Signer(); | ||
verifier.Init(false, new Ed25519PublicKeyParameters(publicKey, 0)); | ||
verifier.BlockUpdate(message, 0, message.Length); | ||
return verifier.VerifySignature(signature); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ public enum Hardfork : byte | |
HF_Aspidochelone, | ||
HF_Basilisk, | ||
HF_Cockatrice, | ||
HF_Domovoi | ||
HF_Domovoi, | ||
HF_Echidna | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.