-
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
50e2c39
commit dfe98c1
Showing
98 changed files
with
493 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-----BEGIN EC PARAMETERS----- | ||
BgUrgQQACg== | ||
-----END EC PARAMETERS----- | ||
-----BEGIN EC PRIVATE KEY----- | ||
MHQCAQEEIHfwyko1dEHTTQ7es7EUy2ajZo1IRRcEC8/9b+MDOzUaoAcGBSuBBAAK | ||
oUQDQgAEuR++wXPjukpxTgFOvIJ7b4man6f0rHac3ihDF6APT2UPCfCapP9aMXYC | ||
Vf5d/IETKbO1C+mRlPyhFhnmXy7f6g== | ||
-----END EC PRIVATE KEY----- |
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,30 @@ | ||
import os | ||
import hashlib | ||
from ecdsa import SigningKey | ||
from ecdsa.util import sigencode_der | ||
from enum import Enum, auto | ||
|
||
|
||
# Private key PEM files have to be named the same (lowercase) as their corresponding enum entries | ||
# Example: for an entry in the Enum named DEV, its PEM file must be at keychain/dev.pem | ||
class Key(Enum): | ||
TRUSTED_NAME = auto() | ||
|
||
|
||
_keys: dict[Key, SigningKey] = dict() | ||
|
||
|
||
# Open the corresponding PEM file and load its key in the global dict | ||
def _init_key(key: Key): | ||
global _keys | ||
with open("%s/keychain/%s.pem" % (os.path.dirname(__file__), key.name.lower())) as pem_file: | ||
_keys[key] = SigningKey.from_pem(pem_file.read(), hashlib.sha256) | ||
assert (key in _keys) and (_keys[key] is not None) | ||
|
||
|
||
# Generate a SECP256K1 signature of the given data with the given key | ||
def sign_data(key: Key, data: bytes) -> bytes: | ||
global _keys | ||
if key not in _keys: | ||
_init_key(key) | ||
return _keys[key].sign_deterministic(data, sigencode=sigencode_der) |
Oops, something went wrong.