mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +02:00
Add set_wif to test frameworks's ECKey
This commit is contained in:
parent
af1bef5c01
commit
cb2d10341a
1 changed files with 9 additions and 0 deletions
|
|
@ -8,6 +8,8 @@ keys, and is trivially vulnerable to side channel attacks. Do not use for
|
|||
anything but tests."""
|
||||
import random
|
||||
|
||||
from .address import base58_to_byte
|
||||
|
||||
def modinv(a, n):
|
||||
"""Compute the modular inverse of a modulo n
|
||||
|
||||
|
|
@ -337,6 +339,13 @@ class ECKey():
|
|||
self.secret = secret
|
||||
self.compressed = compressed
|
||||
|
||||
def set_wif(self, wif):
|
||||
(b, v) = base58_to_byte(wif)
|
||||
if len(b) != 32 and len(b) != 33:
|
||||
raise ValueError("invalid WIF: unexpected length {}".format(len(b)))
|
||||
compressed = len(b) == 33
|
||||
self.set(b[0:32], compressed)
|
||||
|
||||
def generate(self, compressed=True):
|
||||
"""Generate a random private key (compressed or uncompressed)."""
|
||||
self.set(random.randrange(1, SECP256K1_ORDER).to_bytes(32, 'big'), compressed)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue