def testDidBoxNoParams(): didBox = gen.DidBox() assert didBox.seed is not None assert didBox.vk is not None assert didBox.sk is not None assert didBox.did is not None
def keyery(directory): didBox = gen.DidBox() if directory is None: path = "./didery_prerotated_key.json" else: path = os.path.join(directory, "didery_prerotated_key.json") click.echo('Saving new key pair to {}'.format(path)) didBox.save64(path) if directory is None: try: click.prompt( '\nKeys generated in: ' '' '\n\n./didery_prerotated_key.json\n\n' '' 'Make a copy and store them securely. \n' 'The file will be deleted after pressing any key+Enter') os.remove('didery_prerotated_key.json') click.echo('Key files deleted.') except KeyboardInterrupt as ex: if os.path.exists("./didery_prerotated_key.json"): os.remove("./didery_prerotated_key.json") click.echo('Key file deleted.') raise return didBox.base64_vk(), didBox.base64_sk()
def testDidBoxWithSeed(): seed = b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6' didBox = gen.DidBox(seed=seed) assert didBox.seed == seed assert didBox.vk is not None assert didBox.sk is not None assert didBox.did is not None
def testDidBoxWithKeys(): vk = b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5' sk = b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5' didBox = gen.DidBox(vk=vk, sk=sk) assert didBox.seed is None assert didBox.vk == vk assert didBox.sk == sk assert didBox.did is not None
def historyInit(directory): didBoxInit = gen.DidBox() didBoxRot = gen.DidBox() history, vk, sk, pvk, psk = gen.historyGen(didBoxInit.seed, didBoxRot.seed) if directory is None: init_path = "./didery_keys_initial.json" rot_path = "./didery_keys_rotation.json" else: init_path = os.path.join(directory, "didery_keys_initial.json") rot_path = os.path.join(directory, "didery_keys_rotation.json") click.echo('Saving initial key pair to {}'.format(init_path)) click.echo('Saving pre-rotated key pair to {}'.format(rot_path)) didBoxInit.save64(init_path) didBoxRot.save64(rot_path) if directory is None: try: click.prompt( '\nKeys generated in: ' '' '\n\n./didery_keys_initial.json\n' './didery_keys_rotation.json\n\n' '' 'Make a copy and store them securely. \n' 'The file will be deleted after pressing any key+Enter') os.remove("./didery_keys_initial.json") os.remove("./didery_keys_rotation.json") click.echo('Key files deleted.') except KeyboardInterrupt as ex: if os.path.exists("./didery_keys_initial.json"): os.remove("./didery_keys_initial.json") if os.path.exists("./didery_keys_rotation.json"): os.remove("./didery_keys_rotation.json") click.echo('Key files deleted.') raise return history, sk
def getSigningKeys(path=None, keys_to_obtain=1): csk = None psk = None if not path: csk = click.prompt("Enter your current signing/private key") if keys_to_obtain > 1: psk = click.prompt("Enter your pre-rotated signing/private key") else: keys = gen.DidBox() keys.open(path[0]) csk = keys.base64_sk() if keys_to_obtain > 1: keys = gen.DidBox() keys.open(path[1]) psk = keys.base64_sk() return [csk, psk]
def testDidBoxHex_vk(): data = { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =' } didBox = gen.DidBox(data["seed"], data["sk"], data["vk"], data["did"]) assert b'29c8006920a69bb3804369d1965d054e2a62967a7a6e6712e40e48c93a0ad6e5' == didBox.hex_vk()
def testDidBoxBase64_seed(): data = { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =' } didBox = gen.DidBox(data["seed"], data["sk"], data["vk"], data["did"]) base64_seed = 'YYqziW-vxTDxJOJ56uE82Ed7m0VFvfTnX9-Ws0Sf4LY=' assert base64_seed == didBox.base64_seed()
def testDidBoxHex_seed(): data = { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =' } didBox = gen.DidBox(data["seed"], data["sk"], data["vk"], data["did"]) hex_seed = b'618ab3896fafc530f124e279eae13cd8477b9b4545bdf4e75fdf96b3449fe0b6' assert hex_seed == didBox.hex_seed()
def testDidBoxFor_json64(): data = { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =' } didBox = gen.DidBox(data["seed"], data["sk"], data["vk"], data["did"]) exp = { "priv": 'YYqziW-vxTDxJOJ56uE82Ed7m0VFvfTnX9-Ws0Sf4LYpyABpIKabs4BDadGWXQVOKmKWenpuZxLkDkjJOgrW5Q==', "verify": 'KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU=', "seed": 'YYqziW-vxTDxJOJ56uE82Ed7m0VFvfTnX9-Ws0Sf4LY=' } assert exp == didBox.for_json64()
def testDidBoxFor_json(): data = { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =' } didBox = gen.DidBox(data["seed"], data["sk"], data["vk"], data["did"]) exp = { "priv": b'618ab3896fafc530f124e279eae13cd8477b9b4545bdf4e75fdf96b3449fe0b629c8006920a69bb3804369d1965d054e2a62967a7a6e6712e40e48c93a0ad6e5'.decode(), "verify": b'29c8006920a69bb3804369d1965d054e2a62967a7a6e6712e40e48c93a0ad6e5'.decode(), "sign": b'618ab3896fafc530f124e279eae13cd8477b9b4545bdf4e75fdf96b3449fe0b6'.decode() } assert exp == didBox.for_json()
def testDidBoxInitExceptions(): permutations = { "1": { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =', "valid": True }, "2": { "seed": None, "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =', "valid": True }, "3": { "seed": None, "vk": None, "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =', "valid": False, "error": 'Both private and public keys required' }, "4": { "seed": None, "vk": None, "sk": None, "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =', "valid": False, "error": 'Keys required with did' }, "5": { "seed": None, "vk": None, "sk": None, "did": None, "valid": True }, "6": { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": None, "sk": None, "did": None, "valid": True }, "7": { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": None, "did": None, "valid": False, "error": 'Both private and public keys required' }, "8": { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": None, "valid": True }, "9": { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": None, "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =', "valid": False, "error": 'Both private and public keys required' }, "10": { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": None, "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =', "valid": False, "error": 'Both private and public keys required' }, "11": { "seed": None, "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": None, "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =', "valid": False, "error": 'Both private and public keys required' }, "12": { "seed": None, "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": None, "valid": True }, "13": { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": None, "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": None, "valid": False, "error": 'Both private and public keys required' }, "14": { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": None, "sk": None, "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =', "valid": False, "error": 'Keys required with did' }, "15": { "seed": None, "vk": None, "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": None, "valid": False, "error": 'Both private and public keys required' }, "16": { "seed": None, "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": None, "did": None, "valid": False, "error": 'Both private and public keys required' }, "17": { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6', "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =', "valid": False, "error": 'Invalid key' }, "18": { "seed": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6', "vk": b')\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6\xe5', "sk": b'a\x8a\xb3\x89o\xaf\xc50\xf1$\xe2y\xea\xe1<\xd8G{\x9bEE\xbd\xf4\xe7_\xdf\x96\xb3D\x9f\xe0\xb6)\xc8\x00i \xa6\x9b\xb3\x80Ci\xd1\x96]\x05N*b\x96zzng\x12\xe4\x0eH\xc9:\n\xd6', "did": 'did:dad: KcgAaSCmm7OAQ2nRll0FTipilnp6bmcS5A5IyToK1uU =', "valid": False, "error": 'Invalid key' } } for i, data in permutations.items(): if data["valid"]: assert gen.DidBox(data["seed"], data["sk"], data["vk"], data["did"]) else: with pytest.raises(ValueError, message=data["error"]): gen.DidBox(data["seed"], data["sk"], data["vk"], data["did"])