diff --git a/py/converter.py b/py/converter.py index ce3641d..65c8d16 100644 --- a/py/converter.py +++ b/py/converter.py @@ -23,4 +23,40 @@ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -""" \ No newline at end of file +""" +import json +from ecdsa import SigningKey, VerifyingKey, SECP256k1 +from ecdsa.util import PRNG + +f = open('text.txt', 'r') +request = json.load(f) +f.close() + +def p2h(data, keymode): + if(keymode=="sk"): + sk = SigningKey.from_pem(data, curve=SECP256k1) + print(sk.to_string().hex()) + elif(keymode=="vk"): + vk = VerifyingKey.from_pem(data, curve=SECP256k1) + print(vk.to_string().hex()) + +def h2p(data, keymode): + if(keymode=="sk"): + sk = SigningKey.from_string(b16decode(data), curve=SECP256k1) + print(sk.to_pem()) + elif(keymode=="vk"): + vk = VerifyingKey.from_string(b16decode(data), curve=SECP256k1) + print(vk.to_pem()) + +def seed2hkey(data, keymode): + seed = PRNG(data.encode()) + sk = SigningKey.generate(entropy=seed, curve=SECP256k1) + print(sk.to_string().hex()) + +switch = { + "p2h":p2h, + "h2p":h2p, + "seed2hkey":seed2hkey +} + +switch[request["mode"]](request["data"], request("keymode"))