Exemplo n.º 1
0
def method(casperlabs_client: CasperLabsClient, args: Dict):
    deploy = casperlabs_client.make_deploy(
        from_addr=args.get("from"),
        payment=args.get("payment"),
        session=args.get("session"),
        public_key=args.get("public_key"),
        session_args=args.get("session_args"),
        payment_args=args.get("payment_args"),
        payment_amount=args.get("payment_amount"),
        payment_hash=args.get("payment_hash"),
        payment_name=args.get("payment_name"),
        payment_package_hash=args.get("payment_package_hash"),
        payment_package_name=args.get("payment_package_name"),
        session_hash=args.get("session_hash"),
        session_name=args.get("session_name"),
        session_package_hash=args.get("session_package_hash"),
        session_package_name=args.get("session_package_name"),
        ttl_millis=args.get("ttl_millis"),
        dependencies=args.get("dependencies"),
        chain_name=args.get("chain_name"),
        algorithm=args.get("algorithm"),
    )
    data = deploy.SerializeToString()
    if not args.get("deploy_path"):
        sys.stdout.buffer.write(data)
    else:
        io.write_binary_file(args.get("deploy_path"), data)
Exemplo n.º 2
0
def method(casperlabs_client: CasperLabsClient, args: Dict):
    algorithm = args.get("algorithm")
    public_key_path = args.get("public_key")
    file_path = args.get("file_path")

    account_hash = casperlabs_client.account_hash(
        algorithm=algorithm, public_key_pem_path=public_key_path)
    account_hash_hex = account_hash.hex().encode("UTF-8")

    if file_path:
        io.write_binary_file(file_path, account_hash_hex)
    else:
        sys.stdout.buffer.write(account_hash_hex)
Exemplo n.º 3
0
    def save_key_files(self, save_directory: Union[str, Path]) -> None:
        """
        Save key pairs out as public and private pem files.

        :param save_directory:   str or Path to directory for saving pem files.

        Generated files:
            public_key.pem  # public key in pem format
            secret_key.pem  # secret key in pem format
            public_key_hex  # public key in hex format with leading algorithm byte
        """
        private_path = Path(save_directory) / consts.PRIVATE_KEY_FILENAME
        io.write_binary_file(private_path, self.private_key_pem)

        public_path = Path(save_directory) / consts.PUBLIC_KEY_FILENAME
        io.write_binary_file(public_path, self.public_key_pem)

        public_hex_path = Path(save_directory) / consts.PUBLIC_KEY_HEX_FILENAME
        io.write_file(public_hex_path,
                      f"{self._hex_prefix()}{self.public_key_hex}")
Exemplo n.º 4
0
    def save_pem_files(
        self,
        save_directory: Union[str, Path],
        filename_prefix: str = consts.DEFAULT_KEY_FILENAME_PREFIX,
    ) -> None:
        """
        Save key pairs out as public and private pem files.

        :param save_directory:   str or Path to directory for saving pem files.
        :param filename_prefix:  prefix of filename to be used for save.
        """
        private_path = (
            Path(save_directory) /
            f"{filename_prefix}{consts.ACCOUNT_PRIVATE_KEY_FILENAME_SUFFIX}")
        write_binary_file(private_path, self.private_key_pem)

        public_path = (
            Path(save_directory) /
            f"{filename_prefix}{consts.ACCOUNT_PUBLIC_KEY_FILENAME_SUFFIX}")
        write_binary_file(public_path, self.public_key_pem)
Exemplo n.º 5
0
def method(casperlabs_client: CasperLabsClient, args: Dict):
    private_key = args.get("private_key")
    algorithm = args.get("algorithm")
    deploy_path = args.get("deploy_path")
    signed_deploy_path = args.get("signed_deploy_path")
    deploy = None
    if not deploy_path:
        deploy = consensus.Deploy()
        deploy.ParseFromString(sys.stdin.read())

    signed_deploy = casperlabs_client.sign_deploy(
        private_key_pem_file=private_key,
        algorithm=algorithm,
        deploy=deploy,
        deploy_file=deploy_path,
    )
    serialized_deploy = signed_deploy.SerializeToString()
    if signed_deploy_path is None:
        sys.stdout.write(serialized_deploy)
    else:
        io.write_binary_file(signed_deploy_path, serialized_deploy)