当前位置: 首页>>代码示例>>Python>>正文


Python CryptoFactory.new_signer方法代码示例

本文整理汇总了Python中sawtooth_signing.CryptoFactory.new_signer方法的典型用法代码示例。如果您正苦于以下问题:Python CryptoFactory.new_signer方法的具体用法?Python CryptoFactory.new_signer怎么用?Python CryptoFactory.new_signer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sawtooth_signing.CryptoFactory的用法示例。


在下文中一共展示了CryptoFactory.new_signer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
    def __init__(self, delegate, args):
        super(IntKeyWorkload, self).__init__(delegate, args)
        self._auth_info = args.auth_info
        self._urls = []
        self._pending_batches = {}
        self._lock = threading.Lock()
        self._delegate = delegate
        self._deps = {}
        context = create_context('secp256k1')
        crypto_factory = CryptoFactory(context=context)
        if args.key_file is not None:
            try:
                with open(args.key_file, 'r') as infile:
                    signing_key = infile.read().strip()
                private_key = Secp256k1PrivateKey.from_hex(signing_key)

                self._signer = crypto_factory.new_signer(
                    private_key=private_key)
            except ParseError as pe:
                raise IntKeyCliException(str(pe))
            except IOError as ioe:
                raise IntKeyCliException(str(ioe))
        else:
            self._signer = crypto_factory.new_signer(
                context.new_random_private_key())
开发者ID:cianx,项目名称:sawtooth-core,代码行数:27,代码来源:intkey_workload.py

示例2: __init__

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
    def __init__(self, with_genesis=True):
        self.block_sender = MockBlockSender()
        self.batch_sender = MockBatchSender()
        self.dir = tempfile.mkdtemp()
        self.block_db = NativeLmdbDatabase(
            os.path.join(self.dir, 'block.lmdb'),
            BlockStore.create_index_configuration())
        self.block_store = BlockStore(self.block_db)
        self.block_cache = BlockCache(self.block_store)
        self.state_db = NativeLmdbDatabase(
            os.path.join(self.dir, "merkle.lmdb"),
            MerkleDatabase.create_index_configuration())

        self.state_view_factory = NativeStateViewFactory(self.state_db)

        self.block_manager = BlockManager()
        self.block_manager.add_commit_store(self.block_store)

        context = create_context('secp256k1')
        private_key = context.new_random_private_key()
        crypto_factory = CryptoFactory(context)
        self.signer = crypto_factory.new_signer(private_key)

        identity_private_key = context.new_random_private_key()
        self.identity_signer = crypto_factory.new_signer(identity_private_key)
        chain_head = None
        if with_genesis:
            self.genesis_block = self.generate_genesis_block()
            chain_head = self.genesis_block
            self.block_manager.put([chain_head.block])
            self.block_manager.persist(
                chain_head.block.header_signature,
                "commit_store")

        self.block_publisher = BlockPublisher(
            block_manager=self.block_manager,
            transaction_executor=MockTransactionExecutor(),
            transaction_committed=self.block_store.has_transaction,
            batch_committed=self.block_store.has_batch,
            state_view_factory=self.state_view_factory,
            block_sender=self.block_sender,
            batch_sender=self.block_sender,
            chain_head=chain_head.block,
            identity_signer=self.identity_signer,
            data_dir=None,
            config_dir=None,
            permission_verifier=MockPermissionVerifier(),
            batch_observers=[])
开发者ID:cianx,项目名称:sawtooth-core,代码行数:50,代码来源:block_tree_manager.py

示例3: _read_signer

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
def _read_signer(key_filename):
    """Reads the given file as a hex key.

    Args:
        key_filename: The filename where the key is stored. If None,
            defaults to the default key for the current user.

    Returns:
        Signer: the signer

    Raises:
        CliException: If unable to read the file.
    """
    filename = key_filename
    if filename is None:
        filename = os.path.join(os.path.expanduser('~'),
                                '.sawtooth',
                                'keys',
                                getpass.getuser() + '.priv')

    try:
        with open(filename, 'r') as key_file:
            signing_key = key_file.read().strip()
    except IOError as e:
        raise CliException('Unable to read key file: {}'.format(str(e)))

    try:
        private_key = Secp256k1PrivateKey.from_hex(signing_key)
    except ParseError as e:
        raise CliException('Unable to read key in file: {}'.format(str(e)))

    context = create_context('secp256k1')
    crypto_factory = CryptoFactory(context)
    return crypto_factory.new_signer(private_key)
开发者ID:jjason,项目名称:sawtooth-core,代码行数:36,代码来源:sawset.py

示例4: do_populate

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
def do_populate(batches, keys):
    context = create_context('secp256k1')
    private_key = context.new_random_private_key()
    crypto_factory = CryptoFactory(context)
    signer = crypto_factory.new_signer(private_key)

    total_txn_count = 0
    txns = []
    for i in range(0, len(keys)):
        name = list(keys)[i]
        txn = create_intkey_transaction(
            verb='set',
            name=name,
            value=random.randint(9000, 100000),
            deps=[],
            signer=signer)
        total_txn_count += 1
        txns.append(txn)
        # Establish the signature of the txn associated with the word
        # so we can create good dependencies later
        keys[name] = txn.header_signature

    batch = create_batch(
        transactions=txns,
        signer=signer)

    batches.append(batch)
开发者ID:Whiteblock,项目名称:sawtooth-core,代码行数:29,代码来源:create_batch.py

示例5: setUp

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
    def setUp(self):
        self.dir = tempfile.mkdtemp()
        self.block_db = NativeLmdbDatabase(
            os.path.join(self.dir, 'block.lmdb'),
            BlockStore.create_index_configuration())
        self.block_store = BlockStore(self.block_db)
        self.block_manager = BlockManager()
        self.block_manager.add_commit_store(self.block_store)
        self.gossip = MockGossip()
        self.completer = Completer(
            block_manager=self.block_manager,
            transaction_committed=self.block_store.has_transaction,
            get_committed_batch_by_id=self.block_store.get_batch,
            get_committed_batch_by_txn_id=(
                self.block_store.get_batch_by_transaction
            ),
            get_chain_head=lambda: self.block_store.chain_head,
            gossip=self.gossip)
        self.completer.set_on_block_received(self._on_block_received)
        self.completer.set_on_batch_received(self._on_batch_received)
        self._has_block_value = True

        context = create_context('secp256k1')
        private_key = context.new_random_private_key()
        crypto_factory = CryptoFactory(context)
        self.signer = crypto_factory.new_signer(private_key)

        self.blocks = []
        self.batches = []
开发者ID:cianx,项目名称:sawtooth-core,代码行数:31,代码来源:test.py

示例6: __init__

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
    def __init__(self, with_genesis=True):
        self.block_sender = MockBlockSender()
        self.batch_sender = MockBatchSender()
        self.block_store = BlockStore(DictDatabase(
            indexes=BlockStore.create_index_configuration()))
        self.block_cache = BlockCache(self.block_store)
        self.state_db = {}

        # add the mock reference to the consensus
        consensus_setting_addr = SettingsView.setting_address(
            'sawtooth.consensus.algorithm')
        self.state_db[consensus_setting_addr] = _setting_entry(
            'sawtooth.consensus.algorithm', 'test_journal.mock_consensus')

        self.state_view_factory = MockStateViewFactory(self.state_db)
        context = create_context('secp256k1')
        private_key = context.new_random_private_key()
        crypto_factory = CryptoFactory(context)
        self.signer = crypto_factory.new_signer(private_key)

        identity_private_key = context.new_random_private_key()
        self.identity_signer = crypto_factory.new_signer(identity_private_key)
        chain_head = None
        if with_genesis:
            self.genesis_block = self.generate_genesis_block()
            self.set_chain_head(self.genesis_block)
            chain_head = self.genesis_block

        self.block_publisher = BlockPublisher(
            transaction_executor=MockTransactionExecutor(),
            block_cache=self.block_cache,
            state_view_factory=self.state_view_factory,
            settings_cache=SettingsCache(
                SettingsViewFactory(self.state_view_factory),
            ),
            block_sender=self.block_sender,
            batch_sender=self.block_sender,
            squash_handler=None,
            chain_head=chain_head,
            identity_signer=self.identity_signer,
            data_dir=None,
            config_dir=None,
            permission_verifier=MockPermissionVerifier(),
            check_publish_block_frequency=0.1,
            batch_observers=[])
开发者ID:jjason,项目名称:sawtooth-core,代码行数:47,代码来源:block_tree_manager.py

示例7: setUp

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
 def setUp(self):
     context = create_context('secp256k1')
     crypto_factory = CryptoFactory(context)
     private_key = context.new_random_private_key()
     self.signer = crypto_factory.new_signer(private_key)
     self._identity_view_factory = MockIdentityViewFactory()
     self.permissions = {}
     self._identity_cache = IdentityCache(
         self._identity_view_factory)
     self.permission_verifier = \
         PermissionVerifier(
             permissions=self.permissions,
             current_root_func=self._current_root_func,
             identity_cache=self._identity_cache)
开发者ID:jjason,项目名称:sawtooth-core,代码行数:16,代码来源:tests.py

示例8: setUp

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
    def setUp(self):
        self.block_store = BlockStore(DictDatabase(
            indexes=BlockStore.create_index_configuration()))
        self.gossip = MockGossip()
        self.completer = Completer(self.block_store, self.gossip)
        self.completer._on_block_received = self._on_block_received
        self.completer._on_batch_received = self._on_batch_received
        self.completer._has_block = self._has_block
        self._has_block_value = True

        context = create_context('secp256k1')
        private_key = context.new_random_private_key()
        crypto_factory = CryptoFactory(context)
        self.signer = crypto_factory.new_signer(private_key)

        self.blocks = []
        self.batches = []
开发者ID:Whiteblock,项目名称:sawtooth-core,代码行数:19,代码来源:test.py

示例9: do_generate

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
def do_generate(args, batches, keys):
    context = create_context('secp256k1')
    private_key = context.new_random_private_key()
    crypto_factory = CryptoFactory(context)
    signer = crypto_factory.new_signer(private_key)

    start = time.time()
    total_txn_count = 0
    for i in range(0, args.count):
        txns = []
        for _ in range(0, random.randint(1, args.max_batch_size)):
            name = random.choice(list(keys))
            txn = create_intkey_transaction(
                verb=random.choice(['inc', 'dec']),
                name=name,
                value=random.randint(1, 10),
                deps=[keys[name]],
                signer=signer)
            total_txn_count += 1
            txns.append(txn)

        batch = create_batch(
            transactions=txns,
            signer=signer)

        batches.append(batch)

        if i % 100 == 0 and i != 0:
            stop = time.time()

            txn_count = 0
            for batch in batches[-100:]:
                txn_count += len(batch.transactions)

            fmt = 'batches {}, batch/sec: {:.2f}, txns: {}, txns/sec: {:.2f}'
            print(fmt.format(
                str(i),
                100 / (stop - start),
                str(total_txn_count),
                txn_count / (stop - start)))
            start = stop
开发者ID:Whiteblock,项目名称:sawtooth-core,代码行数:43,代码来源:create_batch.py

示例10: test_authorization_challenge_submit_bad_signature

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
    def test_authorization_challenge_submit_bad_signature(self):
        """
        Test the AuthorizationChallengeSubmitHandler returns an
        AuthorizationViolation and closes the connection if the signature
        is not verified.
        """
        context = create_context('secp256k1')
        private_key = context.new_random_private_key()
        crypto_factory = CryptoFactory(context)
        signer = crypto_factory.new_signer(private_key)

        payload = os.urandom(10)

        signature = signer.sign(payload)

        auth_challenge_submit = AuthorizationChallengeSubmit(
            public_key="other",
            signature=signature,
            roles=[RoleType.Value("NETWORK")])

        roles = {"network": AuthorizationType.TRUST}

        network = MockNetwork(
            roles,
            connection_status={
                "connection_id": ConnectionStatus.AUTH_CHALLENGE_REQUEST
            })
        permission_verifer = MockPermissionVerifier()
        gossip = MockGossip()
        handler = AuthorizationChallengeSubmitHandler(
            network, permission_verifer, gossip, {"connection_id": payload})
        handler_status = handler.handle(
            "connection_id",
            auth_challenge_submit.SerializeToString())
        self.assertEqual(handler_status.status, HandlerStatus.RETURN_AND_CLOSE)
        self.assertEqual(
            handler_status.message_type,
            validator_pb2.Message.AUTHORIZATION_VIOLATION)
开发者ID:jjason,项目名称:sawtooth-core,代码行数:40,代码来源:test.py

示例11: load_identity_signer

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
def load_identity_signer(key_dir, key_name):
    """Loads a private key from the key directory, based on a validator's
    identity.

    Args:
        key_dir (str): The path to the key directory.
        key_name (str): The name of the key to load.

    Returns:
        Signer: the cryptographic signer for the key
    """
    key_path = os.path.join(key_dir, '{}.priv'.format(key_name))

    if not os.path.exists(key_path):
        raise LocalConfigurationError(
            "No such signing key file: {}".format(key_path))
    if not os.access(key_path, os.R_OK):
        raise LocalConfigurationError(
            "Key file is not readable: {}".format(key_path))

    LOGGER.info('Loading signing key: %s', key_path)
    try:
        with open(key_path, 'r') as key_file:
            private_key_str = key_file.read().strip()
    except IOError as e:
        raise LocalConfigurationError(
            "Could not load key file: {}".format(str(e)))

    try:
        private_key = Secp256k1PrivateKey.from_hex(private_key_str)
    except signing.ParseError as e:
        raise LocalConfigurationError(
            "Invalid key in file {}: {}".format(key_path, str(e)))

    context = signing.create_context('secp256k1')
    crypto_factory = CryptoFactory(context)
    return crypto_factory.new_signer(private_key)
开发者ID:Whiteblock,项目名称:sawtooth-core,代码行数:39,代码来源:keys.py

示例12: create_chain

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
def create_chain(num=10):
    context = create_context('secp256k1')
    private_key = context.new_random_private_key()
    crypto_factory = CryptoFactory(context)
    signer = crypto_factory.new_signer(private_key)

    counter = 1
    previous_block_id = "0000000000000000"
    blocks = []
    while counter <= num:
        current_block_id = uuid4().hex
        txns = [
            t[0]
            for t in [
                create_transaction(
                    payload=uuid4().hex.encode(), signer=signer)
                for _ in range(20)
            ]
        ]

        txn_ids = [t.header_signature for t in txns]
        batch = create_batch(
            transactions=txns,
            signer=signer)

        blk_w = create_block(
            counter,
            previous_block_id,
            current_block_id,
            batches=[batch])
        blocks.append((current_block_id, blk_w, txn_ids))

        counter += 1
        previous_block_id = current_block_id

    return blocks
开发者ID:Whiteblock,项目名称:sawtooth-core,代码行数:38,代码来源:tests.py

示例13: setUp

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
 def setUp(self):
     self._temp_dir = tempfile.mkdtemp()
     context = create_context('secp256k1')
     private_key = context.new_random_private_key()
     crypto_factory = CryptoFactory(context)
     self._signer = crypto_factory.new_signer(private_key)
开发者ID:Whiteblock,项目名称:sawtooth-core,代码行数:8,代码来源:tests.py

示例14: SchedulerTester

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]

#.........这里部分代码省略.........
                self._batch_id_by_txn_id[txn_id] = batch_id

            b_results[batch_real.header_signature] = BatchExecutionResult(
                is_valid=batch_is_valid,
                state_hash=batch_state_root)
            batches.append(batch_real)
        return batches, b_results

    def _dependencies_are_valid(self, dependencies, previous_batch_results):
        for dep in dependencies:
            if dep in self._batch_id_by_txn_id:
                batch_id = self._batch_id_by_txn_id[dep]
                dep_result = previous_batch_results[batch_id]
                if not dep_result.is_valid:
                    return False
        return True

    def _process_txns(self, batch, previous_batch_results, signer):
        txns = []
        referenced_txns = {}
        execution = {}
        batch_is_valid = True
        for transaction in batch:
            is_valid = True
            addresses_to_set = []
            addresses_to_delete = []
            inputs = transaction['inputs']
            outputs = transaction['outputs']
            inputs_real = [self._address(a) for a in inputs]
            outputs_real = [self._address(a) for a in outputs]
            if self._contains_and_not_none('addresses_to_set', transaction):
                addresses_to_set = [{
                    self._address(a, require_full=True): self._bytes_if_none(
                        d[a])
                    for a in d
                } for d in transaction['addresses_to_set']]
            if self._contains_and_not_none('addresses_to_delete', transaction):
                addresses_to_delete = [
                    self._address(a, require_full=True)
                    for a in transaction['addresses_to_delete']
                ]

            if self._contains_and_not_none('dependencies', transaction):
                if any([
                        a not in self._referenced_txns_in_other_batches
                        and len(a) <= 20 for a in transaction['dependencies']
                ]):
                    # This txn has a dependency with a txn signature that is
                    # not known about,
                    return None

                dependencies = [
                    self._referenced_txns_in_other_batches[a]
                    if a in self._referenced_txns_in_other_batches else a
                    for a in transaction['dependencies']
                ]
                dependencies = [a for a in dependencies if len(a) > 20]
            else:
                dependencies = []

            deps_valid = self._dependencies_are_valid(
                dependencies,
                previous_batch_results)

            if self._contains_and_not_none('valid', transaction):
                is_valid = bool(transaction['valid'])

            if not is_valid or not deps_valid:
                batch_is_valid = False

            txn, _ = create_transaction(
                payload=uuid.uuid4().hex.encode(),
                dependencies=dependencies,
                inputs=inputs_real,
                outputs=outputs_real,
                signer=signer)

            if self._contains_and_not_none('name', transaction):
                referenced_txns[transaction['name']] = txn.header_signature

            execution[txn.header_signature] = (is_valid,
                                               addresses_to_set,
                                               addresses_to_delete)
            txns.append(txn)

        self._txn_execution.update(execution)
        self._referenced_txns_in_other_batches.update(referenced_txns)
        return txns, batch_is_valid

    def _create_batches(self):
        test_yaml = self._yaml_from_file()
        private_key = self._context.new_random_private_key()
        signer = self._crypto_factory.new_signer(private_key)

        batches, batch_results = self._process_batches(
            yaml_batches=test_yaml,
            signer=signer)

        self._batch_results = batch_results
        self._batches = batches
开发者ID:Whiteblock,项目名称:sawtooth-core,代码行数:104,代码来源:yaml_scheduler_tester.py

示例15: get_signer

# 需要导入模块: from sawtooth_signing import CryptoFactory [as 别名]
# 或者: from sawtooth_signing.CryptoFactory import new_signer [as 别名]
def get_signer():
    context = create_context('secp256k1')
    private_key = context.new_random_private_key()
    crypto_factory = CryptoFactory(context)
    return crypto_factory.new_signer(private_key)
开发者ID:Whiteblock,项目名称:sawtooth-core,代码行数:7,代码来源:test_state_verifier.py


注:本文中的sawtooth_signing.CryptoFactory.new_signer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。