[#1] Add cryptography methods
Signed-off-by: ilyas585 <niyazov2023@gmail.com>
This commit is contained in:
parent
480d288e2a
commit
19282f13cc
14 changed files with 268 additions and 0 deletions
26
frostfs_api/cryptography/signer.py
Normal file
26
frostfs_api/cryptography/signer.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
import ecdsa
|
||||
from hashlib import sha256, sha512
|
||||
|
||||
|
||||
class Signer:
|
||||
def sign_rfc6979(self, private_key: bytes, message: bytes) -> bytes:
|
||||
if len(private_key) == 0 or private_key is None:
|
||||
raise ValueError(f"Incorrect private_key: {private_key}")
|
||||
|
||||
sk = ecdsa.SigningKey.from_string(private_key, curve=ecdsa.NIST256p, hashfunc=sha256)
|
||||
|
||||
signature = sk.sign_deterministic(message)
|
||||
|
||||
return signature
|
||||
|
||||
def sign(self, private_key: bytes, message: bytes) -> bytes:
|
||||
if len(private_key) == 0 or private_key is None:
|
||||
raise ValueError(f"Incorrect private key: {private_key}")
|
||||
|
||||
sk = ecdsa.SigningKey.from_string(private_key, curve=ecdsa.NIST256p, hashfunc=sha512)
|
||||
signature = sk.sign(message)
|
||||
|
||||
# the first byte indicates the node version marker
|
||||
signature_with_marker = bytes([0x04]) + signature
|
||||
|
||||
return signature_with_marker
|
Loading…
Add table
Add a link
Reference in a new issue