def create_ed_keys(urandom=os.urandom): sk, pk = make_ed25519_keypair(urandom) pk_human = Base58.encode_version( Base58.VER_NODE_PUBLIC, ED25519_BYTE + pk) sk_human = Base58.encode_version( Base58.VER_NODE_PRIVATE, sk) return pk_human, sk_human
def create_ed_keys(urandom=os.urandom): private_key, public_key = make_ed25519_keypair(urandom) public_key_human = Base58.encode_version(Base58.VER_NODE_PUBLIC, ED25519_BYTE + public_key) private_key_human = Base58.encode_version(Base58.VER_NODE_PRIVATE, private_key) return public_key_human, private_key_human
def create_ed_public_key(private_key_human): v, private_key = Base58.decode_version(private_key_human) check_master_secret(v, private_key) public_key = ed25519.publickey(private_key) public_key_human = Base58.encode_version(Base58.VER_NODE_PUBLIC, ED25519_BYTE + public_key) return public_key_human
def check_validator_public(v, validator_public_key): Base58.check_version(v, Base58.VER_NODE_PUBLIC) if len(validator_public_key) != 33: raise ValueError("Validator key should be length 33, is %s" % len(validator_public_key)) b = ord(validator_public_key[0]) if b not in (2, 3): raise ValueError("First validator key byte must be 2 or 3, is %d" % b)
def create_ed_keys(urandom=os.urandom): private_key, public_key = make_ed25519_keypair(urandom) public_key_human = Base58.encode_version( Base58.VER_NODE_PUBLIC, ED25519_BYTE + public_key) private_key_human = Base58.encode_version( Base58.VER_NODE_PRIVATE, private_key) return public_key_human, private_key_human
def create_ed_public_key(sk_human): v, sk = Base58.decode_version(sk_human) check_secret_key(v, sk) pk = ed25519.publickey(sk) pk_human = Base58.encode_version(Base58.VER_NODE_PUBLIC, ED25519_BYTE + pk) return pk_human
def get_test_keypair(self): public = (Base58.VER_NODE_PUBLIC, '\x02' + (32 * 'v')) private = (Base58.VER_NODE_PRIVATE, 32 * 'k') Sign.check_validator_public(*public) Sign.check_master_secret(*private) return (Base58.encode_version(*public), Base58.encode_version(*private))
def check_validator_public(v, validator_public_key): Base58.check_version(v, Base58.VER_NODE_PUBLIC) if len(validator_public_key) != 33: raise ValueError('Validator key should be length 33, is %s' % len(validator_public_key)) b = ord(validator_public_key[0]) if b not in (2, 3): raise ValueError('First validator key byte must be 2 or 3, is %d' % b)
def check_validation_public_key(v, pk): Base58.check_version(v, Base58.VER_NODE_PUBLIC) if len(pk) != 33: raise ValueError('Validation public key should be length 33, is %s' % len(pk)) b = ord(pk[0]) if b not in (2, 3): raise ValueError('First validation public key byte must be 2 or 3, is %d' % b)
def create_ed_public_key(sk_human): v, sk = Base58.decode_version(sk_human) check_secret_key(v, sk) pk = ed25519.publickey(sk) pk_human = Base58.encode_version( Base58.VER_NODE_PUBLIC, ED25519_BYTE + pk) return pk_human
def verify_signature(seq, validator_public_key_human, public_key_human, signature): v, validator_public_key = Base58.decode_version(validator_public_key_human) check_validator_public(v, validator_public_key) v, public_key = Base58.decode_version(public_key_human) m = make_manifest(public_key, validator_public_key, seq) public_key = public_key[1:] # Remove ED25519_BYTE sig = signature.decode("hex") ed25519.checkvalid(sig, "MAN\0" + m, public_key)
def verify_signature(seq, validator_public_key_human, public_key_human, signature): v, validator_public_key = Base58.decode_version(validator_public_key_human) check_validator_public(v, validator_public_key) v, public_key = Base58.decode_version(public_key_human) m = make_manifest(public_key, validator_public_key, seq) public_key = public_key[1:] # Remove ED25519_BYTE sig = signature.decode('hex') ed25519.checkvalid(sig, 'MAN\0' + m, public_key)
def get_signature(seq, validator_public_key_human, private_key_human): v, validator_public_key = Base58.decode_version(validator_public_key_human) check_validator_public(v, validator_public_key) v, private_key = Base58.decode_version(private_key_human) check_master_secret(v, private_key) pk = ed25519.publickey(private_key) apk = ED25519_BYTE + pk m = make_manifest(apk, validator_public_key, seq) m1 = sign_manifest(m, private_key, pk) return base64.b64encode(m1)
def get_signature(seq, validation_pk_human, validation_sk_human, master_sk_human): v, validation_pk = Base58.decode_version(validation_pk_human) check_validation_public_key(v, validation_pk) v, validation_sk_str = Base58.decode_version(validation_sk_human) check_secret_key(v, validation_sk_str) validation_sk = ecdsa.SigningKey.from_string(validation_sk_str, curve=ecdsa.SECP256k1) v, master_sk = Base58.decode_version(master_sk_human) check_secret_key(v, master_sk) pk = ed25519.publickey(master_sk) apk = ED25519_BYTE + pk m = make_manifest(apk, validation_pk, seq) m1 = sign_manifest(m, validation_sk, master_sk, pk) return base64.b64encode(m1)
def perform_sign(seq, validation_pk_human, validation_sk_human, master_sk_human, print=print): manifest = get_signature(int(seq), validation_pk_human, validation_sk_human, master_sk_human) print('[validator_token]') print( wrap( base64.b64encode( json.dumps( { "validation_secret_key": binascii.b2a_hex( Base58.decode_version(validation_sk_human)[1]), "manifest": manifest }, separators=(',', ':')))))
def test_encode(self): self.assertEquals( Base58.encode_version(Base58.VER_ACCOUNT_PUBLIC, BINARY), 'sB49XwJgmdEZDo8LmYwki7FYkiaN7')
def test_check(self): public = Base58.encode_version(Base58.VER_NODE_PRIVATE, 32 * 'k') Sign.perform_check(public, self.print) self.assertEquals(self.results, [[['version = VER_NODE_PRIVATE'], {}], [['decoded length = 32'], {}]])
def test_decode(self): ver, b = Base58.decode_version('sB49XwJgmdEZDo8LmYwki7FYkiaN7') self.assertEquals(ver, Base58.VER_ACCOUNT_PUBLIC) self.assertEquals(b, BINARY)
def check_master_secret(v, private_key): Base58.check_version(v, Base58.VER_NODE_PRIVATE) if len(private_key) != 32: raise ValueError("Length of master secret should be 32, is %s" % len(private_key))
def create_ed_keys(urandom=os.urandom): sk, pk = make_ed25519_keypair(urandom) pk_human = Base58.encode_version(Base58.VER_NODE_PUBLIC, ED25519_BYTE + pk) sk_human = Base58.encode_version(Base58.VER_NODE_PRIVATE, sk) return pk_human, sk_human
def run_test(self, before, after): self.assertEquals(Base58.decode(before), after) self.assertEquals(Base58.encode(after), before)
def check_secret_key(v, sk): Base58.check_version(v, Base58.VER_NODE_PRIVATE) if len(sk) != 32: raise ValueError('Length of master secret should be 32, is %s' % len(sk))
def test_check(self): self.assertEquals(Base58.checksum(BINARY), '\xaa\xaar\x9d')
def perform_check(s, print=print): version, b = Base58.decode_version(s) print("version = " + Base58.version_name(version)) print("decoded length = " + str(len(b))) assert Base58.encode_version(version, b) == s
def check_master_secret(v, private_key): Base58.check_version(v, Base58.VER_NODE_PRIVATE) if len(private_key) != 32: raise ValueError('Length of master secret should be 32, is %s' % len(private_key))
def perform_check(s, print=print): version, b = Base58.decode_version(s) print('version = ' + Base58.version_name(version)) print('decoded length = ' + str(len(b))) assert Base58.encode_version(version, b) == s