|
| 1 | +# Copyright 2021 Hathor Labs |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import os |
| 16 | +import sys |
| 17 | + |
| 18 | +from cryptography.hazmat.primitives.asymmetric import ec |
| 19 | +from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePrivateKeyWithSerialization |
| 20 | + |
| 21 | + |
| 22 | +def main(): |
| 23 | + from hathor.cli.util import create_parser |
| 24 | + from hathor.crypto.util import ( |
| 25 | + get_address_b58_from_public_key, |
| 26 | + get_private_key_bytes, |
| 27 | + get_public_key_bytes_compressed, |
| 28 | + ) |
| 29 | + parser = create_parser() |
| 30 | + parser.add_argument('--config-yaml', type=str, help='Configuration yaml filepath') |
| 31 | + args = parser.parse_args(sys.argv[1:]) |
| 32 | + if not args.config_yaml: |
| 33 | + raise Exception('`--config-yaml` is required') |
| 34 | + os.environ['HATHOR_CONFIG_YAML'] = args.config_yaml |
| 35 | + |
| 36 | + private_key = ec.generate_private_key(ec.SECP256K1()) |
| 37 | + public_key = private_key.public_key() |
| 38 | + assert isinstance(private_key, EllipticCurvePrivateKeyWithSerialization) |
| 39 | + |
| 40 | + print('Private key (hex):', get_private_key_bytes(private_key=private_key).hex()) |
| 41 | + print('Public key (hex):', get_public_key_bytes_compressed(public_key=public_key).hex()) |
| 42 | + print('Address (base58):', get_address_b58_from_public_key(public_key=public_key)) |
0 commit comments