예제 #1
0
    def _load_coldkeypub(self) -> str:
        if not os.path.isfile(self.coldkeypubfile):
            logger.critical("coldkeypubfile  {} does not exist".format(
                self.coldkeypubfile))
            raise KeyFileError

        if not os.path.isfile(self.coldkeypubfile):
            logger.critical("coldkeypubfile  {} is not a file".format(
                self.coldkeypubfile))
            raise KeyFileError

        if not os.access(self.coldkeypubfile, os.R_OK):
            logger.critical("coldkeypubfile  {} is not readable".format(
                self.coldkeypubfile))
            raise KeyFileError

        with open(self.coldkeypubfile, "r") as file:
            key = file.readline().strip()
            if not re.match("^0x[a-z0-9]{64}$", key):
                raise KeyFileError("Cold key pub file is corrupt")

        with open(self.coldkeypubfile, "r") as file:
            coldkeypub = file.readline().strip()

        logger.success(
            "Loaded coldkey.pub: <cyan>{}</cyan>".format(coldkeypub))
        return coldkeypub
예제 #2
0
    def _load_coldkeypub(self) -> str:
        if not os.path.isfile(self.coldkeypubfile):
            print(
                colored(
                    "coldkeypubfile  {} does not exist".format(
                        self.coldkeypubfile), 'red'))
            raise KeyFileError

        if not os.path.isfile(self.coldkeypubfile):
            print(
                colored(
                    "coldkeypubfile  {} is not a file".format(
                        self.coldkeypubfile), 'red'))
            raise KeyFileError

        if not os.access(self.coldkeypubfile, os.R_OK):
            print(
                colored(
                    "coldkeypubfile  {} is not readable".format(
                        self.coldkeypubfile), 'red'))
            raise KeyFileError

        with open(self.coldkeypubfile, "r") as file:
            key = file.readline().strip()
            if not re.match("^0x[a-z0-9]{64}$", key):
                raise KeyFileError("Cold key pub file is corrupt")

        with open(self.coldkeypubfile, "r") as file:
            coldkeypub = file.readline().strip()

        print(colored("Loaded coldkey.pub: {}".format(coldkeypub), 'green'))
        return coldkeypub
예제 #3
0
    def _load_coldkey(self) -> bittensor.substrate.Keypair:
        if not os.path.isfile( self.coldkeyfile ):
            print(colored("coldkeyfile  {} does not exist".format( self.coldkeyfile ), 'red'))
            raise KeyFileError

        if not os.path.isfile( self.coldkeyfile ):
            print(colored("coldkeyfile  {} is not a file".format( self.coldkeyfile ), 'red'))
            raise KeyFileError

        if not os.access( self.coldkeyfile , os.R_OK):
            print(colored("coldkeyfile  {} is not readable".format( self.coldkeyfile ), 'red'))
            raise KeyFileError

        with open( self.coldkeyfile , 'rb') as file:
            data = file.read()
            try:
                # Try key load.
                if is_encrypted(data):
                    password = bittensor.utils.Cli.ask_password()
                    print("decrypting key... (this may take a few moments)")
                    data = decrypt_data(password, data)
                coldkey = load_keypair_from_data(data)

            except KeyError:
                print(colored("Invalid password", 'red'))
                raise KeyError("Invalid password")

            except KeyFileError as e:
                print(colored("Keyfile corrupt", 'red'))
                raise KeyFileError("Keyfile corrupt")

            print(colored("Loaded coldkey: {}".format(coldkey.public_key), 'green'))
            return coldkey
예제 #4
0
    def _load_hotkey(self):
        keyfile = os.path.expanduser( self.hotkeyfile )
        keyfile = os.path.expanduser(keyfile)

        if not os.path.isfile(keyfile):
            print(colored("hotkeyfile  {} does not exist".format(keyfile), 'red'))
            raise KeyFileError

        if not os.path.isfile(keyfile):
            print(colored("hotkeyfile  {} is not a file".format(keyfile), 'red'))
            raise KeyFileError

        if not os.access(keyfile, os.R_OK):
            print(colored("hotkeyfile  {} is not readable".format(keyfile), 'red'))
            raise KeyFileError

        try:
            with open(keyfile, 'rb') as file:
                data = file.read()
                try:
                    # Try hotkey load.
                    if is_encrypted(data):
                        password = bittensor.utils.Cli.ask_password()
                        print("decrypting key... (this may take a few moments)")
                        data = decrypt_data(password, data)
                    self._hotkey = load_keypair_from_data(data)
                except KeyError:
                    print(colored("Invalid password", 'red'))
                    sys.exit(1)
                except KeyFileError as e:
                    print(colored("Keyfile corrupt", 'red'))
                    sys.exit(1)

                print(colored("Loaded hotkey: {}".format(self._hotkey.public_key), 'green'))

        except KeyError:
            print(colored("Invalid password", 'red'))
            raise KeyError("Invalid password")

        except KeyFileError as e:
            print(colored("Keyfile corrupt", 'red'))
            raise KeyFileError("Keyfile corrupt")
예제 #5
0
    def _load_coldkey(self) -> 'substrateinterface.Keypair':
        if not os.path.isfile(self.coldkeyfile):
            logger.critical("coldkeyfile  {} does not exist".format(
                self.coldkeyfile))
            raise KeyFileError

        if not os.path.isfile(self.coldkeyfile):
            logger.critical("coldkeyfile  {} is not a file".format(
                self.coldkeyfile))
            raise KeyFileError

        if not os.access(self.coldkeyfile, os.R_OK):
            logger.critical("coldkeyfile  {} is not readable".format(
                self.coldkeyfile))
            raise KeyFileError

        with open(self.coldkeyfile, 'rb') as file:
            data = file.read()
            try:
                # Try key load.
                if is_encrypted(data):
                    password = bittensor.utils.Cli.ask_password()
                    logger.info(
                        "decrypting key... (this may take a few moments)")
                    data = decrypt_data(password, data)
                coldkey = load_keypair_from_data(data)

            except KeyError:
                logger.critical("Invalid password")
                raise KeyError("Invalid password")

            except KeyFileError as e:
                logger.critical("Keyfile corrupt")
                raise KeyFileError("Keyfile corrupt")

            logger.success("Loaded coldkey: <cyan>{}</cyan>".format(
                coldkey.public_key))
            return coldkey