From 120da2783b032be0a58d01c1ef40a23dcff88f2b Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sat, 7 Nov 2020 19:26:30 +0100 Subject: [PATCH] util.randrange: use stdlib 'secrets' module instead of 'python-ecdsa' --- electrum/util.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/electrum/util.py b/electrum/util.py index cd45c155f..0ad510e94 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -44,15 +44,15 @@ import ssl import ipaddress from ipaddress import IPv4Address, IPv6Address import random -import attr +import secrets +import attr import aiohttp from aiohttp_socks import ProxyConnector, ProxyType import aiorpcx from aiorpcx import TaskGroup import certifi import dns.resolver -import ecdsa from .i18n import _ from .logging import get_logger, Logger @@ -1306,7 +1306,9 @@ def resolve_dns_srv(host: str): def randrange(bound: int) -> int: """Return a random integer k such that 1 <= k < bound, uniformly distributed across that range.""" - return ecdsa.util.randrange(bound) + # secrets.randbelow(bound) returns a random int: 0 <= r < bound, + # hence transformations: + return secrets.randbelow(bound - 1) + 1 class CallbackManager: