Ejemplo n.º 1
0
 def __init__(self, sk: SigningKey, server_id: VerifyingKey, kid: bytes):
     self.sk = sk
     self.vk = sk.get_verifying_key()
     self.server_id = server_id
     self.kid = kid
     self.session = EdhocSession()
     super().__init__()
Ejemplo n.º 2
0
 def create_signature(self, private_key: ecdsa.SigningKey):
     transaction_data = self.raw_transaction
     sender_verifying_key = ecdsa.VerifyingKey.from_string(transaction_data.get('sender'))
     # raise sender_verifying_key
     if sender_verifying_key != private_key.get_verifying_key():
         raise ValueError('SigningKey is not the sender')
     self.signature = self.sign(private_key)
Ejemplo n.º 3
0
    def __init__(self, sk: SigningKey):
        self.sk: SigningKey = sk
        self.vk: VerifyingKey = sk.get_verifying_key()
        self.peer_identities = {}
        self.sessions = []
        self.security_contexts = {}
        self.pop_key_by_rid = {}

        super().__init__()
Ejemplo n.º 4
0
def to_pubkey(privkey_obj: ecdsa.SigningKey) -> bytes:  # pragma: nocover
    """
        Return compressed public key encoding
        Adapted from prusnak's bip32utils
        https://github.com/prusnak/bip32utils/
        https://github.com/prusnak/bip32utils/blob/master/LICENSE
        """
    pubkey_obj = privkey_obj.get_verifying_key()
    padx = (b'\0' * 32 + int_to_string(pubkey_obj.pubkey.point.x()))[-32:]
    if pubkey_obj.pubkey.point.y() & 1:
        ck = b'\3' + padx
    else:
        ck = b'\2' + padx
    return ck
Ejemplo n.º 5
0
def make_tx(key: ecdsa.SigningKey, contract, func, arguments={}):
    tx = {
        'sender': key.get_verifying_key().to_string().hex(),
        'signature': None,
        'payload': {
            'contract': contract,
            'function': func,
            'arguments': arguments
        }
    }

    message = encode(tx['payload']).encode()

    signature = key.sign_deterministic(message, hashlib.sha256)[:64]

    tx['signature'] = signature.hex()

    return tx
Ejemplo n.º 6
0
raw_tx = rlp.encode(tx)
raw_tx_hex = b'0x' + hexlify(raw_tx)

# Signed transaction is like a signed cheque, anyone can drop at a bank
tx_hash = w3rpc.eth.sendRawTransaction(raw_tx_hex)
tx_receipt = w3rpc.eth.getTransactionReceipt(tx_hash)
print(tx_receipt)

# https://rinkeby.etherscan.io/tx/0x01e12e91a0f889039b9116cdbf3733b2f8d3fb2ccb2b74074fee7a6c63c49b87

################################################################

# Illustration for transaction signature verification
# First, make a copy of the signed transaction
decoded_raw_tx = rlp.decode(raw_tx)
signature = decoded_raw_tx[7] + decoded_raw_tx[8]

# We need to recover the unsigned transaction
unsigned_tx = list(decoded_raw_tx)
unsigned_tx[6] = b'\x04' # v = ChainID = Rinkeby
unsigned_tx[7] = b''     # r = 0
unsigned_tx[8] = b''     # s = 0

# Signed message is simply RLP encoding of the unsigned transaction
msg = rlp.encode(unsigned_tx)

# Verify unsigned transaction against the signature in the signed transaction
sk = SigningKey(secexp, curve=SECP256k1, hashfunc=keccak_256)
vk = sk.get_verifying_key()
vk.verify(signature, msg)
Ejemplo n.º 7
0
def get_verification_key(sk: ecdsa.SigningKey) -> ecdsa.VerifyingKey:
    return sk.get_verifying_key()
Ejemplo n.º 8
0
def verifying_key(signing_key: SigningKey) -> VerifyingKey:
    return signing_key.get_verifying_key()
Ejemplo n.º 9
0
def signing_key_to_address(key: SigningKey) -> str:
    # based on
    # https://www.reddit.com/r/ethereum/comments/69qfkv/python_script_that_converts_ethereum_private_key/
    verifying_key = key.get_verifying_key()
    return verifying_key_to_address(verifying_key)