|
35 | 35 |
|
36 | 36 | from . import constants, util, lnutil |
37 | 37 | from . import bitcoin |
| 38 | +from . import crandom |
38 | 39 | from .util import ( |
39 | 40 | profiler, OldTaskGroup, ESocksProxy, NetworkRetryManager, JsonRPCClient, NotEnoughFunds, EventListener, |
40 | 41 | event_listener, bfh, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions, ignore_exceptions, |
@@ -664,7 +665,7 @@ class LNGossip(Logger): |
664 | 665 |
|
665 | 666 | def __init__(self, config: 'SimpleConfig'): |
666 | 667 | self.config = config |
667 | | - seed = os.urandom(32) |
| 668 | + seed = crandom.get_rand_bytes(32) |
668 | 669 | node = BIP32Node.from_rootseed(seed, xtype='standard') |
669 | 670 | xprv = node.to_xprv() |
670 | 671 | node_keypair = generate_keypair(BIP32Node.from_xkey(xprv), LnKeyFamily.NODE_KEY) |
@@ -1695,7 +1696,7 @@ async def _open_channel_coroutine( |
1695 | 1696 | public=public, |
1696 | 1697 | zeroconf=zeroconf, |
1697 | 1698 | opening_fee=opening_fee, |
1698 | | - temp_channel_id=os.urandom(32)) |
| 1699 | + temp_channel_id=crandom.get_rand_bytes(32)) |
1699 | 1700 | chan, funding_tx = await util.wait_for2(coro, LN_P2P_NETWORK_TIMEOUT) |
1700 | 1701 | util.trigger_callback('channels_updated', self.wallet) |
1701 | 1702 | self.wallet.adb.add_transaction(funding_tx) # save tx as local into the wallet |
@@ -1752,7 +1753,7 @@ def make_local_config_for_new_channel( |
1752 | 1753 | channel_seed: bytes | None = None, |
1753 | 1754 | ) -> LocalConfig: |
1754 | 1755 | if channel_seed is None: |
1755 | | - channel_seed = os.urandom(32) |
| 1756 | + channel_seed = crandom.get_rand_bytes(32) |
1756 | 1757 | initial_msat = funding_sat * 1000 - push_msat if initiator == LOCAL else push_msat |
1757 | 1758 |
|
1758 | 1759 | # sending empty bytes as the upfront_shutdown_script will give us the |
@@ -2508,7 +2509,7 @@ async def create_routes_for_payment( |
2508 | 2509 | budget=budget._replace(fee_msat=budget.fee_msat // len(per_trampoline_channel_amounts)), |
2509 | 2510 | ) |
2510 | 2511 | # node_features is only used to determine is_tlv |
2511 | | - per_trampoline_secret = os.urandom(32) |
| 2512 | + per_trampoline_secret = crandom.get_rand_bytes(32) |
2512 | 2513 | per_trampoline_fees = per_trampoline_amount_with_fees - per_trampoline_amount |
2513 | 2514 | self.logger.info(f'created route with trampoline fee level={paysession.trampoline_fee_level}') |
2514 | 2515 | self.logger.info(f'trampoline hops: {[hop.end_node.hex() for hop in trampoline_route]}') |
@@ -2776,7 +2777,7 @@ def create_payment_info( |
2776 | 2777 | ) -> bytes: |
2777 | 2778 | if amount_msat == 0: |
2778 | 2779 | raise ValueError("amount_msat must not be 0. Use None instead.") |
2779 | | - payment_preimage = os.urandom(32) |
| 2780 | + payment_preimage = crandom.get_rand_bytes(32) |
2780 | 2781 | payment_hash = sha256(payment_preimage) |
2781 | 2782 | min_final_cltv_delta = min_final_cltv_delta or MIN_FINAL_CLTV_DELTA_ACCEPTED |
2782 | 2783 | invoice_features = self._prepare_invoice_features(self.features.for_bolt11_invoice(), amount_msat=amount_msat) |
@@ -4175,7 +4176,7 @@ async def _maybe_forward_trampoline( |
4175 | 4176 | payload = any_trampoline_onion.hop_data.payload |
4176 | 4177 | payment_data = payload.get('payment_data') |
4177 | 4178 | try: |
4178 | | - payment_secret = payment_data['payment_secret'] if payment_data else os.urandom(32) |
| 4179 | + payment_secret = payment_data['payment_secret'] if payment_data else crandom.get_rand_bytes(32) |
4179 | 4180 | outgoing_node_id = payload["outgoing_node_id"]["outgoing_node_id"] |
4180 | 4181 | amt_to_forward = payload["amt_to_forward"]["amt_to_forward"] |
4181 | 4182 | out_cltv_abs = payload["outgoing_cltv_value"]["outgoing_cltv_value"] |
@@ -4332,7 +4333,7 @@ def create_onion_for_route( |
4332 | 4333 | for i in range(len(route)): |
4333 | 4334 | self.logger.info(f" {i}: edge={route[i].short_channel_id} hop_data={hops_data[i]!r}") |
4334 | 4335 | assert final_cltv_abs <= cltv_abs, (final_cltv_abs, cltv_abs) |
4335 | | - session_key = os.urandom(32) # session_key |
| 4336 | + session_key = crandom.get_rand_bytes(32) # session_key |
4336 | 4337 | # if we are forwarding a trampoline payment, add trampoline onion |
4337 | 4338 | if trampoline_onion: |
4338 | 4339 | self.logger.info(f'adding trampoline onion to final payload') |
|
0 commit comments