-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f53274
commit 291dba8
Showing
104 changed files
with
472 additions
and
177 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
import hashlib | ||
from ecdsa import SigningKey | ||
from ecdsa.util import sigencode_der | ||
|
||
|
||
class KeySigner: | ||
def __init__(self, pem_name: str): | ||
""" | ||
Initialize the KeySigner instance with a specific PEM file. | ||
:param pem_name: Name of the PEM file (without extension), e.g., 'trusted_name' | ||
""" | ||
pem_path = os.path.join(os.path.dirname(__file__), f"{pem_name}") | ||
if not os.path.exists(pem_path): | ||
raise FileNotFoundError(f"PEM file not found: {pem_path}") | ||
|
||
with open(pem_path, "r") as pem_file: | ||
self._signing_key = SigningKey.from_pem(pem_file.read(), hashlib.sha256) | ||
|
||
def sign_data(self, data: bytes) -> bytes: | ||
""" | ||
Generate a SECP256K1 signature of the given data. | ||
:param data: Data to sign as bytes. | ||
:return: Signature as bytes in DER format. | ||
""" | ||
return self._signing_key.sign_deterministic(data, sigencode=sigencode_der) |
File renamed without changes.
File renamed without changes.
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.