コード例 #1
0
    def sign(self, key):
        """Sets the signature for this block.

        Args:
            key (bytes): Private key to be used to sign.
        """

        self.signature = sign(self.hash, key)
コード例 #2
0
    def confirm(self, index, key):
        """Adds a confirmation signature for this transaction.

        Args:
            index (int): Index of the input owner by the signer.
            key (bytes): Private key to be used to sign.
        """

        self.confirmations[index] = sign(self.confirmation_hash, key)
コード例 #3
0
 def register(self, sender, privateKey):
     msg = "hi"
     messageHash = sha3(msg)
     sig = sign(messageHash, privateKey)
     self.root_chain.register(messageHash,
                              sig,
                              transact={
                                  'from': sender,
                                  'gas': 40000000
                              })
コード例 #4
0
def test_signature_scheme_respects_verifying_contract(testlang, utxo):
    alice = testlang.accounts[0]
    outputs = [(alice.address, NULL_ADDRESS, 50)]
    spend_id = testlang.spend_utxo([utxo.spend_id], [alice.key], outputs)

    testlang.start_standard_exit(spend_id, alice.key)
    exit_id = testlang.get_standard_exit_id(spend_id)

    spend_tx = Transaction(inputs=[decode_utxo_id(spend_id)], outputs=outputs)

    bad_contract_signature = sign(hash_struct(spend_tx, verifyingContract=None), alice.key)

    # challenge will fail on signature verification
    with pytest.raises(TransactionFailed):
        testlang.root_chain.challengeStandardExit(exit_id, spend_tx.encoded, 0, bad_contract_signature)

    # sanity check
    proper_signature = sign(hash_struct(spend_tx, verifyingContract=testlang.root_chain), alice.key)
    testlang.root_chain.challengeStandardExit(exit_id, spend_tx.encoded, 0, proper_signature)
コード例 #5
0
def test_old_signature_scheme_does_not_work_any_longer(testlang, utxo):
    # In this test I will challenge standard exit with old signature schema to show it no longer works
    # Then passing new signature to the same challenge data, challenge will succeed
    alice = testlang.accounts[0]
    outputs = [(alice.address, NULL_ADDRESS, 50)]
    spend_id = testlang.spend_utxo([utxo.spend_id], [alice.key], outputs)

    testlang.start_standard_exit(spend_id, alice.key)
    exit_id = testlang.get_standard_exit_id(spend_id)

    # let's prepare old schema signature for a transaction with an input of exited utxo
    spend_tx = Transaction(inputs=[decode_utxo_id(spend_id)], outputs=outputs)
    old_signature = sign(spend_tx.hash, alice.key)

    # challenge will fail on signature verification
    with pytest.raises(TransactionFailed):
        testlang.root_chain.challengeStandardExit(exit_id, spend_tx.encoded, 0, old_signature)

    # sanity check: let's provide new schema signature for a challenge
    new_signature = sign(hash_struct(spend_tx, verifyingContract=testlang.root_chain), alice.key)
    testlang.root_chain.challengeStandardExit(exit_id, spend_tx.encoded, 0, new_signature)
コード例 #6
0
    def confirm_spend(self, tx_id, signer):
        """Signs a confirmation signature for a spend.

        Args:
            tx_id (int): Identifier of the transaction.
            signer (EthereumAccount): Account to sign this confirmation.
        """

        spend_tx = self.child_chain.get_transaction(tx_id)
        (blknum, _, _) = decode_utxo_id(tx_id)
        block = self.child_chain.blocks[blknum]
        confirmation_hash = sha3(spend_tx.hash + block.root)
        self.confirmations[tx_id] = sign(confirmation_hash, signer.key)
コード例 #7
0
ファイル: block.py プロジェクト: sthorpe/plasma-contracts
 def sign(self, key):
     self.sig = sign(self.hash, key)
コード例 #8
0
 def sign2(self, key):
     self.sig2 = sign(self.hash, key)
コード例 #9
0
 def sign1(self, key):
     self.sig1 = sign(self.hash, key)
コード例 #10
0
 def confirm(self, root, key):
     return sign(utils.sha3(self.hash + root), key)
コード例 #11
0
 def sign(self, index, key):
     self.signatures[index] = sign(self.hash, key)
コード例 #12
0
ファイル: block.py プロジェクト: kendricktan/plasma-contracts
 def sign(self, key):
     return SignedBlock(self, sign(self.hash, key))
コード例 #13
0
 def sign(self, index, key, verifyingContract=None):
     hash = hash_struct(self, verifyingContract=verifyingContract)
     sig = sign(hash, key)
     self.signatures[index] = sig
     self._signers[index] = get_signer(hash, sig) if sig != NULL_SIGNATURE else NULL_ADDRESS
コード例 #14
0
def confirm_tx(tx, root, key):
    return sign(u.sha3(tx.hash + root), key)
コード例 #15
0
def test_signature(t, block):
    block.sign(t.k0)
    assert block.sig == sign(block.hash, t.k0)
    assert block.signer == get_signer(block.hash, sign(block.hash, t.k0))
コード例 #16
0
 def sign(self, key):
     self.signature = sign(self.hash, key)