def load_keyfile(fn): with open(fn, 'r') as f: key = eval(f.read()) if key['type'] == 'ed25519': fid = bytes.fromhex(key['public']) signer = crypto.ED25519(bytes.fromhex(key['private'])) elif key['type'] == 'hmac_sha256': fid = bytes.fromhex(key['feed_id']) signer = crypto.HMAC256(bytes.fromhex(key['private'])) return fid, signer
def load_keyfile(fn): with open(fn, 'r') as f: key = eval(f.read()) if key['type'] == 'ed25519': fid = bytes.fromhex(key['public']) signer = crypto.ED25519(bytes.fromhex(key['private'])) digestmod = 'sha256' elif key['type'] in ['hmac_sha256', 'hmac_sha1', 'hmac_md5']: fid = bytes.fromhex(key['feed_id']) digestmod = key['type'][5:] signer = crypto.HMAC(digestmod, bytes.fromhex(key['private'])) return fid, signer, digestmod
def get_signer(self) -> crypto.ED25519: """ This function identifies the signer of the user Parameters ---------- self : USER The alias name of the user Returns ------- crypto.ED25519 Signer of the user """ return crypto.ED25519(bytes.fromhex(self.sk))
def new() -> USER: """ This function creates a new user. Returns ------- USER new created user """ key_pair = crypto.ED25519() key_pair.create() u = USER(fid=key_pair.get_public_key().hex(), sk=key_pair.get_private_key().hex(), follows=[], channels=[]) if u.save(): return u return None