pyrxd.security — Typed primitives + errors¶
Security primitives for pyrxd.
This package contains the security foundation the rest of the SDK is built on: exception hierarchy, key-material wrappers, secure RNG helpers, and typed newtypes enforcing trust-boundary invariants.
Nothing in this package should ever log, print, or format raw key material.
- class pyrxd.security.BlockHeight[source]¶
Bases:
intNon-negative block height with a generous sanity ceiling.
- exception pyrxd.security.CovenantError[source]¶
Bases:
RxdSdkErrorRaised for covenant construction or verification failures.
- class pyrxd.security.Hex20[source]¶
Bases:
_FixedBytesExactly 20 raw bytes (e.g. a hash160 public-key hash).
- exception pyrxd.security.KeyMaterialError[source]¶
Bases:
RxdSdkErrorRaised for errors touching private keys, mnemonics, or WIFs.
Constructors raising this error MUST NOT include the offending key material in the message — pass a static description only.
- class pyrxd.security.Nbits[source]¶
Bases:
bytesThe compact difficulty target (nBits) from a block header.
Wire format¶
- nBits is a 4-byte little-endian encoding of a uint32. When decoded:
exponent = nBits_uint32 >> 24(high byte, little-endian: byte[3])mantissa = nBits_uint32 & 0x007fffff(low 3 bytes)target = mantissa * 256^(exponent-3)
This type accepts the raw 4 wire bytes and validates the three conditions Bitcoin Core enforces on target-word parsing. A malformed nBits can be used to forge PoW (e.g. a negative target evaluates the comparison weirdly, a zero target is trivially satisfied, an over-large exponent shifts out of range). Rejecting these at the trust boundary protects every SPV check downstream.
- exception pyrxd.security.NetworkError[source]¶
Bases:
RxdSdkErrorRaised for transport / RPC / network failures.
- class pyrxd.security.Photons[source]¶
Bases:
intNon-negative integer amount in photons (RXD smallest unit).
- class pyrxd.security.PrivateKeyMaterial[source]¶
Bases:
SecretBytesA
SecretByteswhose contents are a valid secp256k1 private key.- Invariants enforced at construction:
length is exactly 32 bytes
integer value is in the valid scalar range
[1, N-1]
- classmethod from_wif(wif)[source]¶
Decode a WIF-encoded private key.
On failure raises
KeyMaterialErrorWITHOUT embedding the inputwifin the message — an attacker watching logs must not learn any part of the candidate key.Implementation is self-contained (no heavy coincurve dependency) so the security module can be imported before the rest of the SDK.
- Parameters:
wif (str)
- Return type:
- class pyrxd.security.RawTx[source]¶
Bases:
bytesRaw transaction bytes.
Enforces the 64-byte Merkle-forgery defense: any candidate transaction must be strictly greater than 64 bytes. A 64-byte “transaction” can be forged from an internal Merkle-tree node, letting an attacker prove inclusion of bogus data. See audit finding 02-F-1 and Bitcoin BIP-141’s segwit commitment for the historical context (and the CVE-2017-12842 family for concrete exploits).
- exception pyrxd.security.RxdSdkError[source]¶
Bases:
ExceptionBase class for every exception raised by pyrxd.
Applying
redactto each positional arg on construction defends against accidental key-material leakage when callers pass user-supplied values straight into the exception.
- class pyrxd.security.Satoshis[source]¶
Bases:
intNon-negative integer amount in satoshis, capped at Bitcoin max supply.
- class pyrxd.security.SecretBytes[source]¶
Bases:
objectA wrapper around
bytesthat will not leak its contents on repr/str.The internal storage is a
bytearraysozeroize()can mutate it in place.unsafe_raw_bytesreturns an immutablebytescopy.- classmethod from_hex(h)[source]¶
Construct from a hex string.
The hex string itself is not embedded in any error message — an attacker who can see the exception must not learn the invalid input was “0x…” with specific bytes.
- Parameters:
h (str)
- Return type:
- class pyrxd.security.SighashFlag[source]¶
Bases:
intA valid Radiant sighash flag byte.
- exception pyrxd.security.SpvVerificationError[source]¶
Bases:
RxdSdkErrorRaised when an SPV proof (Merkle path, header chain) fails to verify.
- exception pyrxd.security.ValidationError[source]¶
Bases:
RxdSdkErrorRaised when input fails a trust-boundary validation check.
- pyrxd.security.redact(value)[source]¶
Return a redacted representation of
valueif it looks sensitive.strlonger than 8 chars that looks like key material ->"<redacted>"byteslonger than 8 bytes ->"<redacted:Nb>"other types -> returned unchanged
- pyrxd.security.secure_random_bytes(n)[source]¶
Return
ncryptographically secure random bytes.Thin wrapper over
secrets.token_bytes(). Exists so callers have a single chokepoint to audit/mock and so then <= 0guard lives in one place.
- pyrxd.security.secure_scalar_mod_n()[source]¶
Draw a uniform random scalar in
[1, N-1]and return it wrapped.Convenience wrapper combining
pyrxd.security.rng.secure_scalar_bytes_mod_n()withPrivateKeyMaterial. Lives in this module (notrng) sornghas no dependency onPrivateKeyMaterial— that keeps the import graph acyclic.- Return type: