Exemple #1
0
 public static new EthereumEcdsaNative Generate(IAccountDerivation accountFactory)
 {
     using (AutoObjectPool <Secp256k1> .Get(out var secp256k1))
     {
         return(Generate(0, secp256k1, accountFactory));
     }
 }
Exemple #2
0
        static EthereumEcdsaBouncyCastle GenerateSingle(uint accountIndex, IAccountDerivation accountFactory)
        {
            var privateKey = accountFactory.GeneratePrivateKey(accountIndex);
            var keyBigInt  = BigIntegerConverter.GetBigInteger(privateKey, signed: false, byteCount: PRIVATE_KEY_SIZE);

            keyBigInt = Secp256k1Curve.EnforceLowS(keyBigInt);

            // Return our private key instance.
            return(new EthereumEcdsaBouncyCastle(privateKey, EthereumEcdsaKeyType.Private));
        }
Exemple #3
0
 public static new IEnumerable <EthereumEcdsaNative> Generate(int count, IAccountDerivation accountFactory)
 {
     using (AutoObjectPool <Secp256k1> .Get(out var secp256k1))
     {
         for (uint i = 0; i < count; i++)
         {
             yield return(Generate(i, secp256k1, accountFactory));
         }
     }
 }
Exemple #4
0
 /// <summary>
 /// Creates an ECDSA instance with a freshly generated keypair.
 /// </summary>
 /// <returns>Returns the ECDSA instance which has the generated keypair.</returns>
 public static EthereumEcdsa Generate(IAccountDerivation accountFactory)
 {
     if (UseNativeLib)
     {
         return(EthereumEcdsaNative.Generate(accountFactory));
     }
     else
     {
         return(EthereumEcdsaBouncyCastle.Generate(accountFactory));
     }
 }
Exemple #5
0
 /// <summary>
 /// Creates an ECDSA instance with a freshly generated keypair.
 /// </summary>
 /// <returns>Returns the ECDSA instance which has the generated keypair.</returns>
 public static IEnumerable <EthereumEcdsa> Generate(int count, IAccountDerivation accountFactory)
 {
     if (UseNativeLib)
     {
         return(EthereumEcdsaNative.Generate(count, accountFactory));
     }
     else
     {
         return(EthereumEcdsaBouncyCastle.Generate(count, accountFactory));
     }
 }
Exemple #6
0
        /// <summary>
        /// Creates an ECDSA instance with a freshly generated keypair.
        /// </summary>
        /// <returns>Returns the ECDSA instance which has the generated keypair.</returns>
        public static EthereumEcdsa Generate(IAccountDerivation accountFactory = null)
        {
            // If the account factory is null, we use a random factory
            if (accountFactory == null)
            {
                accountFactory = new SystemRandomAccountDerivation();
            }

            // Determine which library to use
            if (UseNativeLib)
            {
                return(EthereumEcdsaNative.Generate(accountFactory));
            }
            else
            {
                return(EthereumEcdsaBouncyCastle.Generate(accountFactory));
            }
        }
Exemple #7
0
        static EthereumEcdsaNative Generate(uint accountIndex, Secp256k1 secp256k1, IAccountDerivation accountFactory)
        {
            var privateKey = accountFactory.GeneratePrivateKey(accountIndex);

            if (!secp256k1.SecretKeyVerify(privateKey))
            {
                var errMsg = "Unmanaged EC library failed to valid private key. ";
                if (IncludeKeyDataInExceptions)
                {
                    errMsg += $"Private key: {privateKey.ToHexString()}";
                }

                throw new Exception(errMsg);
            }

            var keyBigInt = BigIntegerConverter.GetBigInteger(privateKey, signed: false, byteCount: PRIVATE_KEY_SIZE);

            keyBigInt  = Secp256k1Curve.EnforceLowS(keyBigInt);
            privateKey = BigIntegerConverter.GetBytes(keyBigInt, PRIVATE_KEY_SIZE);

            return(new EthereumEcdsaNative(privateKey, EthereumEcdsaKeyType.Private));
        }
Exemple #8
0
 public static new IEnumerable <EthereumEcdsaBouncyCastle> Generate(int count, IAccountDerivation accountFactory)
 {
     for (uint i = 0; i < count; i++)
     {
         yield return(GenerateSingle(i, accountFactory));
     }
 }
Exemple #9
0
 public static new EthereumEcdsaBouncyCastle Generate(IAccountDerivation accountFactory)
 {
     return(GenerateSingle(0, accountFactory));
 }