コード例 #1
0
    def _extended_key(self, ver_bytes, raw_serkey):
        '''Return the 78-byte extended key given prefix version bytes and
        serialized key bytes.
        '''
        if not isinstance(ver_bytes, (bytes, bytearray)):
            raise TypeError('ver_bytes must be raw bytes')
        if len(ver_bytes) != 4:
            raise ValueError('ver_bytes must have length 4')
        if not isinstance(raw_serkey, (bytes, bytearray)):
            raise TypeError('raw_serkey must be raw bytes')
        if len(raw_serkey) != 33:
            raise ValueError('raw_serkey must have length 33')

        return (ver_bytes + bytes([self.depth])
                + self.parent_fingerprint() + pack_be_uint32(self.n)
                + self.chain_code + raw_serkey)
コード例 #2
0
def test_block(block_details):
    coin, block_info = block_details
    raw_block = unhexlify(block_info['block'])
    block = coin.block(raw_block, block_info['height'])
    h = coin.electrum_header(block.header, block_info['height'])
    assert block_info['merkleroot'] == h['merkle_root']
    assert block_info['time'] == h['timestamp']
    assert block_info['previousblockhash'] == h['prev_block_hash']
    assert block_info['height'] == h['block_height']
    assert block_info['nonce'] == h['nonce']
    assert block_info['bits'] == pack_be_uint32(h['bits']).hex()

    assert coin.header_hash(block.header) == hex_str_to_hash(
        block_info['hash'])
    assert (coin.header_prevhash(block.header) == hex_str_to_hash(
        block_info['previousblockhash']))
    for n, (tx, txid) in enumerate(block.transactions):
        assert txid == hex_str_to_hash(block_info['tx'][n])
コード例 #3
0
    def child(self, n):
        '''Return the derived child extended pubkey at index N.'''
        if not 0 <= n < (1 << 31):
            raise ValueError('invalid BIP32 public key child number')

        msg = self.pubkey_bytes + pack_be_uint32(n)
        L, R = self._hmac_sha512(msg)

        curve = self.CURVE
        L = bytes_to_int(L)
        if L >= curve.order:
            raise DerivationError

        point = curve.generator * L + self.ec_point()
        if point == EC.INFINITY:
            raise DerivationError

        verkey = ecdsa.VerifyingKey.from_public_point(point, curve=curve)

        return PubKey(verkey, R, n, self.depth + 1, self)
コード例 #4
0
    def child(self, n):
        '''Return the derived child extended privkey at index N.'''
        if not 0 <= n < (1 << 32):
            raise ValueError('invalid BIP32 private key child number')

        if n >= self.HARDENED:
            serkey = b'\0' + self.privkey_bytes
        else:
            serkey = self.public_key.pubkey_bytes

        msg = serkey + pack_be_uint32(n)
        L, R = self._hmac_sha512(msg)

        curve = self.CURVE
        L = bytes_to_int(L)
        exponent = (L + bytes_to_int(self.privkey_bytes)) % curve.order
        if exponent == 0 or L >= curve.order:
            raise DerivationError

        privkey = _exponent_to_bytes(exponent)

        return PrivKey(privkey, R, n, self.depth + 1, self)
コード例 #5
0
ファイル: db.py プロジェクト: JustinTArthur/electrumx
 def undo_key(self, height: int) -> bytes:
     '''DB key for undo information at the given height.'''
     return b'U' + pack_be_uint32(height)