From 35c500cf14309152c946b723ce4c3dca27161c3e Mon Sep 17 00:00:00 2001 From: jeffthibault Date: Sat, 21 Jan 2023 14:10:57 -0500 Subject: [PATCH] add function to mine vanity key --- nostr/key.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nostr/key.py b/nostr/key.py index 17cf537..1e6fb3f 100644 --- a/nostr/key.py +++ b/nostr/key.py @@ -108,6 +108,17 @@ class PrivateKey: def __eq__(self, other): return self.raw_secret == other.raw_secret +def mine_vanity_key(prefix: str = None, suffix: str = None) -> PrivateKey: + while True: + attempts += 1 + sk = PrivateKey() + if prefix is not None and not sk.public_key.bech32()[5:5+len(prefix)] == prefix: + continue + if suffix is not None and not sk.public_key.bech32()[-len(suffix):] == suffix: + continue + break + + return sk ffi = FFI() @ffi.callback("int (unsigned char *, const unsigned char *, const unsigned char *, void *)")