Exemplo n.º 1
0
def generate_signed_legacy(address: bytes, output: Output):
    decoded_address = Base58.decode(address)
    claim = OldClaimMessage()
    claim.ParseFromString(
        unhexlify(
            '080110011aee04080112a604080410011a2b4865726520617265203520526561736f6e73204920e29da4e'
            'fb88f204e657874636c6f7564207c20544c4722920346696e64206f7574206d6f72652061626f7574204e'
            '657874636c6f75643a2068747470733a2f2f6e657874636c6f75642e636f6d2f0a0a596f752063616e206'
            '6696e64206d65206f6e20746865736520736f6369616c733a0a202a20466f72756d733a2068747470733a'
            '2f2f666f72756d2e6865617679656c656d656e742e696f2f0a202a20506f64636173743a2068747470733'
            'a2f2f6f6666746f706963616c2e6e65740a202a2050617472656f6e3a2068747470733a2f2f7061747265'
            '6f6e2e636f6d2f7468656c696e757867616d65720a202a204d657263683a2068747470733a2f2f7465657'
            '37072696e672e636f6d2f73746f7265732f6f6666696369616c2d6c696e75782d67616d65720a202a2054'
            '77697463683a2068747470733a2f2f7477697463682e74762f786f6e64616b0a202a20547769747465723'
            'a2068747470733a2f2f747769747465722e636f6d2f7468656c696e757867616d65720a0a2e2e2e0a6874'
            '7470733a2f2f7777772e796f75747562652e636f6d2f77617463683f763d4672546442434f535f66632a0'
            'f546865204c696e75782047616d6572321c436f7079726967687465642028636f6e746163742061757468'
            '6f722938004a2968747470733a2f2f6265726b2e6e696e6a612f7468756d626e61696c732f46725464424'
            '34f535f666352005a001a41080110011a30040e8ac6e89c061f982528c23ad33829fd7146435bf7a4cc22'
            'f0bff70c4fe0b91fd36da9a375e3e1c171db825bf5d1f32209766964656f2f6d70342a5c080110031a406'
            '2b2dd4c45e364030fbfad1a6fefff695ebf20ea33a5381b947753e2a0ca359989a5cc7d15e5392a0d354c'
            '0b68498382b2701b22c03beb8dcb91089031b871e72214feb61536c007cdf4faeeaab4876cb397feaf6b51'
        ))
    claim.ClearField("publisherSignature")
    digest = sha256(b''.join(
        [decoded_address,
         claim.SerializeToString(), output.claim_hash[::-1]]))
    signature = output.private_key.sign_digest_deterministic(
        digest, hashfunc=hashlib.sha256)
    claim.publisherSignature.version = 1
    claim.publisherSignature.signatureType = 1
    claim.publisherSignature.signature = signature
    claim.publisherSignature.certificateId = output.claim_hash[::-1]
    return claim
Exemplo n.º 2
0
 def test_query_interpolation(self):
     self.maxDiff = None
     # tests that interpolation replaces longer keys first
     self.assertEqual(
         interpolate(*query(
             "select * from foo",
             a__not='b',
             b__in='select * from blah where c=:$c',
             d__any={
                 'one__like': 'o',
                 'two': 2
             },
             a0=3,
             a00=1,
             a00a=2,
             a00aa=4,  # <-- breaks without correct interpolation key order
             ahash=sha256(b'hello world'),
             limit=10,
             order_by='b',
             **{'$c': 3})),
         "select * from foo WHERE a != 'b' AND "
         "b IN (select * from blah where c=3) AND "
         "(one LIKE 'o' OR two = 2) AND "
         "a0 = 3 AND a00 = 1 AND a00a = 2 AND a00aa = 4 "
         "AND ahash = X'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9' "
         "ORDER BY b LIMIT 10")
Exemplo n.º 3
0
 async def get_local_status_and_history(self, address, history=None):
     if not history:
         address_details = await self.db.get_address(address=address)
         history = (address_details['history']
                    if address_details else '') or ''
     parts = history.split(':')[:-1]
     return (hexlify(sha256(history.encode())).decode() if history else
             None, list(zip(parts[0::2], map(int, parts[1::2]))))
Exemplo n.º 4
0
def verify(channel, data, signature, channel_hash=None):
    pieces = [
        signature['signing_ts'].encode(), channel_hash or channel.claim_hash,
        data
    ]
    return Output.is_signature_valid(
        get_encoded_signature(signature['signature']),
        sha256(b''.join(pieces)), channel.claim.channel.public_key_bytes)
Exemplo n.º 5
0
 async def create_tx_from_nothing(self, my_account, height):
     to_address = await my_account.receiving.get_or_create_usable_address()
     to_hash = Ledger.address_to_hash160(to_address)
     tx = Transaction(height=height, is_verified=True) \
         .add_inputs([self.txi(self.txo(1, sha256(str(height).encode())))]) \
         .add_outputs([self.txo(1, to_hash)])
     await self.ledger.db.insert_transaction(tx)
     await self.ledger.db.save_transaction_io(tx, to_address, to_hash, '')
     return tx
Exemplo n.º 6
0
def sign(channel, data):
    timestamp = str(int(time.time()))
    pieces = [timestamp.encode(), channel.claim_hash, data]
    digest = sha256(b''.join(pieces))
    signature = channel.private_key.sign_digest_deterministic(
        digest, hashfunc=hashlib.sha256)
    return {
        'signature': binascii.hexlify(signature).decode(),
        'signing_ts': timestamp
    }
Exemplo n.º 7
0
 def sign(self, channel: 'Output', first_input_id=None):
     self.channel = channel
     self.signable.signing_channel_hash = channel.claim_hash
     digest = sha256(b''.join([
         first_input_id or self.tx_ref.tx.inputs[0].txo_ref.hash,
         self.signable.signing_channel_hash,
         self.signable.to_message_bytes()
     ]))
     self.signable.signature = channel.private_key.sign_digest_deterministic(digest, hashfunc=hashlib.sha256)
     self.script.generate()
Exemplo n.º 8
0
 async def test_sign_some_content(self):
     some_content = "MEANINGLESS CONTENT AEE3353320".encode()
     timestamp_str = "1630564175"
     channel = await get_channel()
     signature = channel.sign_data(some_content, timestamp_str)
     pieces = [timestamp_str.encode(), channel.claim_hash, some_content]
     self.assertTrue(
         Output.is_signature_valid(unhexlify(signature.encode()),
                                   sha256(b''.join(pieces)),
                                   channel.claim.channel.public_key_bytes))
Exemplo n.º 9
0
def sign_reaction(reaction: dict, channel: Output):
    timestamp = str(int(time.time()))
    signing_field = reaction['channel_name']
    pieces = [timestamp.encode(), channel.claim_hash, signing_field.encode()]
    digest = sha256(b''.join(pieces))
    signature = channel.private_key.sign_digest_deterministic(digest, hashfunc=hashlib.sha256)
    reaction.update({
        'signature': binascii.hexlify(signature).decode(),
        'signing_ts': timestamp
    })
Exemplo n.º 10
0
def sign_comment(comment: dict, channel: Output, sign_comment_id=False):
    timestamp = str(int(time.time()))
    signing_field = comment['comment_id'] if sign_comment_id else comment['comment']
    pieces = [timestamp.encode(), channel.claim_hash, signing_field.encode()]
    digest = sha256(b''.join(pieces))
    signature = channel.private_key.sign_digest_deterministic(digest, hashfunc=hashlib.sha256)
    comment.update({
        'signature': binascii.hexlify(signature).decode(),
        'signing_ts': timestamp
    })
Exemplo n.º 11
0
 def get_signature_digest(self, ledger):
     if self.signable.unsigned_payload:
         pieces = [
             Base58.decode(self.get_address(ledger)),
             self.signable.unsigned_payload,
             self.signable.signing_channel_hash[::-1]
         ]
     else:
         pieces = [
             self.tx_ref.tx.inputs[0].txo_ref.hash,
             self.signable.signing_channel_hash,
             self.signable.to_message_bytes()
         ]
     return sha256(b''.join(pieces))
Exemplo n.º 12
0
 async def test_checkpointed_writer(self):
     headers = Headers(':memory:')
     getblocks = lambda start, end: HEADERS[block_bytes(start):block_bytes(
         end)]
     headers.checkpoint = 10, hexlify(sha256(getblocks(10, 11)))
     async with headers.checkpointed_connector() as buff:
         buff.write(getblocks(0, 10))
     self.assertEqual(len(headers), 10)
     async with headers.checkpointed_connector() as buff:
         buff.write(getblocks(10, 19))
     self.assertEqual(len(headers), 19)
     headers = Headers(':memory:')
     async with headers.checkpointed_connector() as buff:
         buff.write(getblocks(0, 19))
     self.assertEqual(len(headers), 19)
Exemplo n.º 13
0
def is_comment_signed_by_channel(comment: dict, channel: Output, sign_comment_id=False):
    if isinstance(channel, Output):
        try:
            signing_field = comment['comment_id'] if sign_comment_id else comment['comment']
            pieces = [
                comment['signing_ts'].encode(),
                cid2hash(comment['channel_id']),
                signing_field.encode()
            ]
            return Output.is_signature_valid(
                get_encoded_signature(comment['signature']),
                sha256(b''.join(pieces)),
                channel.claim.channel.public_key_bytes
            )
        except KeyError:
            pass
    return False
Exemplo n.º 14
0
 def hash(self):
     if self._hash is None:
         self._hash = sha256(sha256(self.tx.raw_sans_segwit))
     return self._hash
Exemplo n.º 15
0
 def sign_data(self, data: bytes, timestamp: str) -> str:
     pieces = [timestamp.encode(), self.claim_hash, data]
     digest = sha256(b''.join(pieces))
     signature = self.private_key.sign_compact(digest)
     return hexlify(signature).decode()
Exemplo n.º 16
0
 def sign_data(self, data: bytes, timestamp: str) -> str:
     pieces = [timestamp.encode(), self.claim_hash, data]
     digest = sha256(b''.join(pieces))
     signature = self.private_key.sign_digest_deterministic(
         digest, hashfunc=hashlib.sha256)
     return hexlify(signature).decode()