1
0
mirror of https://github.com/bitcoin/bips.git synced 2026-05-18 16:59:30 +00:00

Squashed 'bip-0352/secp256k1lab/' content from commit 44dc4bd

git-subtree-dir: bip-0352/secp256k1lab
git-subtree-split: 44dc4bd893b8f03e621585e3bf255253e0e0fbfb
This commit is contained in:
Sebastian Falbesoner
2026-03-02 19:16:00 +01:00
commit 53b590e190
13 changed files with 680 additions and 0 deletions

15
src/secp256k1lab/keys.py Normal file
View File

@@ -0,0 +1,15 @@
from .secp256k1 import GE, G
from .util import int_from_bytes
# The following function is based on the BIP 327 reference implementation
# https://github.com/bitcoin/bips/blob/master/bip-0327/reference.py
# Return the plain public key corresponding to a given secret key
def pubkey_gen_plain(seckey: bytes) -> bytes:
d0 = int_from_bytes(seckey)
if not (1 <= d0 <= GE.ORDER - 1):
raise ValueError("The secret key must be an integer in the range 1..n-1.")
P = d0 * G
assert not P.infinity
return P.to_bytes_compressed()