[#3] Move to netstandard 2.0
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
ae3fc419a4
commit
0c4723c705
55 changed files with 2508 additions and 1818 deletions
|
@ -1,7 +1,10 @@
|
|||
using System.Buffers.Binary;
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Org.BouncyCastle.Asn1.Sec;
|
||||
|
||||
namespace FrostFS.SDK.Cryptography;
|
||||
|
@ -22,8 +25,10 @@ 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);
|
||||
|
||||
return point.GetEncoded(true);
|
||||
}
|
||||
|
||||
|
@ -34,8 +39,10 @@ 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);
|
||||
|
||||
return point.GetEncoded(false);
|
||||
}
|
||||
|
||||
|
@ -46,10 +53,12 @@ public static class KeyExtension
|
|||
$"{nameof(CreateSignatureRedeemScript)} argument isn't compressed public key. " +
|
||||
$"expected length={CompressedPublicKeyLength}, actual={publicKey.Length}"
|
||||
);
|
||||
|
||||
var script = new byte[] { 0x0c, CompressedPublicKeyLength }; //PUSHDATA1 33
|
||||
script = ArrayHelper.Concat(script, publicKey);
|
||||
script = ArrayHelper.Concat(script, new byte[] { 0x41 }); //SYSCALL
|
||||
script = ArrayHelper.Concat(script, BitConverter.GetBytes(CheckSigDescriptor)); //Neo_Crypto_CheckSig
|
||||
|
||||
return script;
|
||||
}
|
||||
|
||||
|
@ -64,15 +73,20 @@ public static class KeyExtension
|
|||
Span<byte> data = stackalloc byte[21];
|
||||
data[0] = version;
|
||||
scriptHash.CopyTo(data[1..]);
|
||||
|
||||
return Base58.Base58CheckEncode(data);
|
||||
}
|
||||
|
||||
private static byte[] GetPrivateKeyFromWIF(string wif)
|
||||
{
|
||||
if (wif == null) throw new ArgumentNullException();
|
||||
if (wif == null)
|
||||
throw new ArgumentNullException();
|
||||
|
||||
var data = wif.Base58CheckDecode();
|
||||
|
||||
if (data.Length != 34 || data[0] != 0x80 || data[33] != 0x01)
|
||||
throw new FormatException();
|
||||
|
||||
var privateKey = new byte[32];
|
||||
Buffer.BlockCopy(data, 1, privateKey, 0, privateKey.Length);
|
||||
Array.Clear(data, 0, data.Length);
|
||||
|
@ -92,6 +106,7 @@ public static class KeyExtension
|
|||
$" isn't encoded compressed public key. " +
|
||||
$"expected length={CompressedPublicKeyLength}, actual={publicKey.Length}"
|
||||
);
|
||||
|
||||
return publicKey.GetScriptHash().ToAddress(NeoAddressVersion);
|
||||
}
|
||||
|
||||
|
@ -130,12 +145,14 @@ public static class KeyExtension
|
|||
Y = publicKey[32..]
|
||||
}
|
||||
});
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
public static ECDsa LoadWif(this string wif)
|
||||
{
|
||||
var privateKey = GetPrivateKeyFromWIF(wif);
|
||||
|
||||
return LoadPrivateKey(privateKey);
|
||||
}
|
||||
|
||||
|
@ -151,6 +168,7 @@ public static class KeyExtension
|
|||
Y = publicKeyFull[32..]
|
||||
}
|
||||
});
|
||||
|
||||
return key;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue