Ejemplo n.º 1
0
    def sign(self, account=None, **kwargs):
        """ Sign a message with an account's memo key

            :param str account: (optional) the account that owns the bet
                (defaults to ``default_account``)

            :returns: the signed message encapsulated in a known format
        """
        if not account:
            if "default_account" in config:
                account = config["default_account"]
        if not account:
            raise ValueError("You need to provide an account")

        # Data for message
        account = Account(account, bitshares_instance=self.bitshares)
        info = self.bitshares.info()
        meta = dict(timestamp=info["time"],
                    block=info["head_block_number"],
                    memokey=account["options"]["memo_key"],
                    account=account["name"])

        # wif key
        wif = self.bitshares.wallet.getPrivateKeyForPublicKey(
            account["options"]["memo_key"])

        # signature
        message = self.message.strip()
        signature = hexlify(
            sign_message(SIGNED_MESSAGE_META.format(**locals()),
                         wif)).decode("ascii")

        message = self.message
        return SIGNED_MESSAGE_ENCAPSULATED.format(MESSAGE_SPLIT=MESSAGE_SPLIT,
                                                  **locals())
Ejemplo n.º 2
0
 def test_sign_message_cryptography(self):
     if not ecdsa.CRYPTOGRAPHY_AVAILABLE:
         return
     ecdsa.SECP256K1_MODULE = "cryptography"
     signature = ecdsa.sign_message("Foobar", wif)
     pub_key_sig = ecdsa.verify_message("Foobar", signature)
     self.assertEqual(hexlify(pub_key_sig).decode("latin"), pub_key)
Ejemplo n.º 3
0
 def test_sign_message_secp256k1(self):
     if not ecdsa.SECP256K1_AVAILABLE:
         return
     ecdsa.SECP256K1_MODULE = "secp256k1"
     signature = ecdsa.sign_message("Foobar", wif)
     pub_key_sig = ecdsa.verify_message("Foobar", signature)
     self.assertEqual(hexlify(pub_key_sig).decode("latin"), pub_key)
Ejemplo n.º 4
0
def build_tx(account, WIF):
    message = account
    signature = Signature(sign_message(message, WIF))
    # signature2 = Signature(sign_message(account, WIF))
    # logger.info(hexlify(signature2.data).decode('ascii'))
    d = {'account':account}
    d['signature'] = hexlify(signature.data).decode('ascii')
    return d
Ejemplo n.º 5
0
def build_tx(account, WIF):
    op = Tx(**{
            'account': account,
        })
    message = bytes(op)
    digest = hashlib.sha256(message).digest()
    signature = Signature(sign_message(message, WIF))
    d = op.json()
    d['signature'] = hexlify(signature.data).decode('ascii')
    return d
Ejemplo n.º 6
0
def test_sign_message():
    signature = sign_message(
        "text text text",
        "5JCvGL2GVVpjDrKzbKWPHEvuwFs5HdEGwr4brp8RQiwrpEFcZNP")

    # assert(hexlify(signature) == b'2075625adc5f0a025fa5125e1f1a6493c2ad9798ec18afb49d4a1d9f741ccac16'
    #                              b'441cb10d240046e5cf3b7f10694b62c608047ec037b2ddaec053bdd1f5107c927')

    k = verify_message("text text text", signature)

    p = PublicKey(hexlify(k).decode('ascii'))

    assert (str(p) == "SCR5bgzuweaHx231escVuPVxgudSyUWdKAH7fKgxZfp3nKSirzFRa")
Ejemplo n.º 7
0
    def sign(self, account=None, **kwargs):
        """ Sign a message with an account's memo key

            :param str account: (optional) the account that owns the bet
                (defaults to ``default_account``)
            :raises ValueError: If not account for signing is provided

            :returns: the signed message encapsulated in a known format
        """
        if not account:
            if "default_account" in self.blockchain.config:
                account = self.blockchain.config["default_account"]
        if not account:
            raise ValueError("You need to provide an account")

        # Data for message
        account = self.account_class(account,
                                     blockchain_instance=self.blockchain)
        info = self.blockchain.info()
        meta = dict(
            timestamp=info["time"],
            block=info["head_block_number"],
            memokey=account["options"]["memo_key"],
            account=account["name"],
        )

        # wif key
        wif = self.blockchain.wallet.getPrivateKeyForPublicKey(
            account["options"]["memo_key"])

        # We strip the message here so we know for sure there are no trailing
        # whitespaces or returns
        message = self.message.strip()

        enc_message = self.SIGNED_MESSAGE_META.format(**locals())

        # signature
        signature = hexlify(sign_message(enc_message, wif)).decode("ascii")

        self.signed_by_account = account
        self.signed_by_name = account["name"]
        self.meta = meta
        self.plain_message = message

        return self.SIGNED_MESSAGE_ENCAPSULATED.format(
            MESSAGE_SPLIT=self.MESSAGE_SPLIT, **locals())
Ejemplo n.º 8
0
 def __init__(self, ip, port):
     self.stream = Buffer()
     self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.s.connect((ip, port))
     raw_pk = self.s.recv(33)
     self.pk = GraphenePublicKey(raw_pk.hex())
     sk = PrivateKey()
     point = self.pk.point() * int.from_bytes(bytes(sk), "big")
     x: int = point.x()
     raw_data = x.to_bytes(32, "big")
     self.shared_secret = sha512(raw_data).digest()
     key = sha256(self.shared_secret).digest()
     crc = cityhash.CityHash128(self.shared_secret)
     data = crc.to_bytes(16, "little")
     iv = data[8:16] + data[:8]
     self.s.sendall(bytes.fromhex(repr(sk.pubkey)))
     self.encryptor = AES.new(key, AES.MODE_CBC, iv)
     self.test = AES.new(key, AES.MODE_CBC, iv)
     self.decryptor = AES.new(key, AES.MODE_CBC, iv)
     self.worker_thread = threading.Thread(target=self.worker)
     self.worker_thread.start()
     self.send(
         5006, {
             "user_agent":
             "Haruka Mock Client",
             "core_protocol_version":
             106,
             "inbound_address":
             "0.0.0.0",
             "inbound_port":
             0,
             "outbound_port":
             0,
             "node_public_key":
             sk.pubkey,
             "signed_shared_secret":
             ecdsa.sign_message(self.shared_secret, str(sk)),
             "chain_id":
             bytes.fromhex(
                 "4018d7844c78f6a6c41c6a552b898022310fc5dec06da467ee7905a8dad512c8"
             ),
             "user_data": {
                 "platform": String("unknown")
             }
         })
Ejemplo n.º 9
0
    async def sign(self, account=None, **kwargs):
        """ Sign a message with an account's memo key

            :param str account: (optional) the account that owns the bet
                (defaults to ``default_account``)
            :raises ValueError: If not account for signing is provided

            :returns: the signed message encapsulated in a known format
        """
        if not account:
            if "default_account" in self.blockchain.config:
                account = self.blockchain.config["default_account"]
        if not account:
            raise ValueError("You need to provide an account")

        # Data for message
        account = await self.account_class(account,
                                           blockchain_instance=self.blockchain)

        # wif key
        wif = self.blockchain.wallet.getPrivateKeyForPublicKey(
            account["options"]["memo_key"])

        payload = [
            "from",
            account["name"],
            "key",
            account["options"]["memo_key"],
            "time",
            str(datetime.utcnow()),
            "text",
            self.message,
        ]
        enc_message = json.dumps(payload, separators=(",", ":"))

        # signature
        signature = hexlify(sign_message(enc_message, wif)).decode("ascii")

        return dict(signed=enc_message, payload=payload, signature=signature)
Ejemplo n.º 10
0
def sign(message, wifKeys):
    signature = ecdsa.sign_message(message, wifKeys)
    return signature
Ejemplo n.º 11
0
 def test_sign_message(self):
     signature = ecdsa.sign_message("Foobar", wif)
     pub_key_sig = ecdsa.verify_message("Foobar", signature)
     self.assertEqual(hexlify(pub_key_sig).decode("latin"), pub_key)