[#1] Add object Get operation + code quality
Signed-off-by: Ivan Pchelintsev <i.pchelintsev@yadro.com>
This commit is contained in:
parent
9aa93d123d
commit
b307c2c899
17 changed files with 182 additions and 99 deletions
|
@ -22,8 +22,8 @@ public static class KeyExtension
|
|||
$"{nameof(Compress)} argument isn't uncompressed public key. " +
|
||||
$"expected length={UncompressedPublicKeyLength}, actual={publicKey.Length}"
|
||||
);
|
||||
var secp256r1 = SecNamedCurves.GetByName("secp256r1");
|
||||
var point = secp256r1.Curve.DecodePoint(publicKey);
|
||||
var secp256R1 = SecNamedCurves.GetByName("secp256r1");
|
||||
var point = secp256R1.Curve.DecodePoint(publicKey);
|
||||
return point.GetEncoded(true);
|
||||
}
|
||||
|
||||
|
@ -34,8 +34,8 @@ public static class KeyExtension
|
|||
$"{nameof(Decompress)} argument isn't compressed public key. " +
|
||||
$"expected length={CompressedPublicKeyLength}, actual={publicKey.Length}"
|
||||
);
|
||||
var secp256r1 = SecNamedCurves.GetByName("secp256r1");
|
||||
var point = secp256r1.Curve.DecodePoint(publicKey);
|
||||
var secp256R1 = SecNamedCurves.GetByName("secp256r1");
|
||||
var point = secp256R1.Curve.DecodePoint(publicKey);
|
||||
return point.GetEncoded(false);
|
||||
}
|
||||
|
||||
|
@ -115,19 +115,19 @@ public static class KeyExtension
|
|||
return key.ExportParameters(true).D;
|
||||
}
|
||||
|
||||
public static ECDsa LoadPrivateKey(this byte[] private_key)
|
||||
public static ECDsa LoadPrivateKey(this byte[] privateKey)
|
||||
{
|
||||
var secp256r1 = SecNamedCurves.GetByName("secp256r1");
|
||||
var public_key =
|
||||
secp256r1.G.Multiply(new Org.BouncyCastle.Math.BigInteger(1, private_key)).GetEncoded(false)[1..];
|
||||
var secp256R1 = SecNamedCurves.GetByName("secp256r1");
|
||||
var publicKey =
|
||||
secp256R1.G.Multiply(new Org.BouncyCastle.Math.BigInteger(1, privateKey)).GetEncoded(false)[1..];
|
||||
var key = ECDsa.Create(new ECParameters
|
||||
{
|
||||
Curve = ECCurve.NamedCurves.nistP256,
|
||||
D = private_key,
|
||||
D = privateKey,
|
||||
Q = new ECPoint
|
||||
{
|
||||
X = public_key[..32],
|
||||
Y = public_key[32..]
|
||||
X = publicKey[..32],
|
||||
Y = publicKey[32..]
|
||||
}
|
||||
});
|
||||
return key;
|
||||
|
@ -135,20 +135,20 @@ public static class KeyExtension
|
|||
|
||||
public static ECDsa LoadWif(this string wif)
|
||||
{
|
||||
var private_key = GetPrivateKeyFromWIF(wif);
|
||||
return LoadPrivateKey(private_key);
|
||||
var privateKey = GetPrivateKeyFromWIF(wif);
|
||||
return LoadPrivateKey(privateKey);
|
||||
}
|
||||
|
||||
public static ECDsa LoadPublicKey(this byte[] public_key)
|
||||
public static ECDsa LoadPublicKey(this byte[] publicKey)
|
||||
{
|
||||
var public_key_full = public_key.Decompress()[1..];
|
||||
var publicKeyFull = publicKey.Decompress()[1..];
|
||||
var key = ECDsa.Create(new ECParameters
|
||||
{
|
||||
Curve = ECCurve.NamedCurves.nistP256,
|
||||
Q = new ECPoint
|
||||
{
|
||||
X = public_key_full[..32],
|
||||
Y = public_key_full[32..]
|
||||
X = publicKeyFull[..32],
|
||||
Y = publicKeyFull[32..]
|
||||
}
|
||||
});
|
||||
return key;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue