Skip to content

Instantly share code, notes, and snippets.

# === Curve setup: secp256k1 ===
F = FiniteField(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F)
n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
E = EllipticCurve([F(0), F(7)])
G = E.lift_x(F(0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798))
# --- Hash function H: SHA256 → integer mod n (BIP340 tagged hash) ---
def H_bip340_challenge(data):
import hashlib
tag = b"BIP0340/challenge"
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Date: May 12, 2025
Chaintip: 000000000000000000020f4edda4f3360a96d80c49e2c8590dadd02f8808a432
For a number of reasons, I have recently set up a new OpenPGP key,
and will be transitioning away from my old one.
The old key will continue to be valid for some time, but I prefer all
use bip39::Mnemonic;
use bitcoin::absolute::LockTime;
use bitcoin::bip32::{DerivationPath, Xpriv, Xpub};
use bitcoin::consensus::{deserialize, serialize};
use bitcoin::hex::{Case, DisplayHex, FromHex};
use bitcoin::{secp256k1, transaction, Network, OutPoint, Psbt, Script, Sequence, Transaction, TxIn, TxOut};
use miniscript::psbt::PsbtExt;
use miniscript::{DefiniteDescriptorKey, Descriptor, DescriptorPublicKey};
use std::str::FromStr;
@jaonoctus
jaonoctus / kelly.rs
Last active February 13, 2025 13:06
use bip39::Mnemonic;
use bitcoin::absolute::LockTime;
use bitcoin::bip32::{DerivationPath, Xpriv, Xpub};
use bitcoin::consensus::{deserialize, serialize};
use bitcoin::hex::{Case, DisplayHex, FromHex};
use bitcoin::{secp256k1, transaction, Network, OutPoint, Psbt, Script, Sequence, Transaction, TxIn, TxOut};
use miniscript::psbt::PsbtExt;
use miniscript::{DefiniteDescriptorKey, Descriptor, DescriptorPublicKey};
use std::str::FromStr;
use bitcoin::hashes::{sha256, Hash};
# If that is inacceptable, pick as internal key a "Nothing Up My Sleeve" (NUMS) point,
# i.e., a point with unknown discrete logarithm.
# One example of such a point is H = lift_x(0x50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0)
# which is constructed by taking the hash of the standard uncompressed encoding of the secp256k1 base point G as X coordinate.
# In order to avoid leaking the information that key path spending is not possible
# it is recommended to pick a fresh integer r in the range 0...n-1 uniformly at random and use H + rG as internal key.
# It is possible to prove that this internal key does not have a known discrete logarithm with respect to G
# by revealing r to a verifier who can then reconstruct how the internal key was created.
import hashlib
[Interface]
PrivateKey = YPRIV
Address = 10.0.0.2/24
# DNS = 1.1.1.1
[Peer]
PublicKey = XPUB
AllowedIPs = 10.0.0.0/24
Endpoint = XPUBLICIP:51820
PersistentKeepalive = 25
// Convert decimal difficulty to target hex
function difficultyToTarget(difficulty) {
// maxTarget is the hex target for difficulty 1
const maxTarget = BigInt("0x00000000FFFF0000000000000000000000000000000000000000000000000000");
// Convert difficulty to BigInt and handle decimal places
const difficultyBigInt = BigInt(Math.floor(difficulty * 100000000)) / BigInt(100000000);
// Calculate target: maxTarget / difficulty
const target = maxTarget / difficultyBigInt;
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
I'm jaonoctus, in control of my PGP key 0x782C165A293D6E18.
writing this and signing with my new subkey ed25519/0x4FE21F5FFF84C9BC created at 2024-10-08 that will expire at 2025-10-08.
Latest bitcoin block hash:
00000000000000000000e1eba946427ab210ec3b9d9d3f7cedd93a73228c38ab
-----BEGIN PGP SIGNATURE-----
testnet=1
rpcauth=bitcoin:1cbc10237553f3b301516af8c1a74ad1$a8606448b6b01a2e63639d58111b92773c89b42b9435009b6f03bd2199446afc
zmqpubrawblock=tcp://0.0.0.0:28332
zmqpubrawtx=tcp://0.0.0.0:28333
[network]
listen=1
whitelist=0.0.0.0/0
[rpc]
#!/bin/bash
# dependencies: base58
# usage
# ./xpub-converter.sh <ZPUB> xpub
main () {
local input="$1"
local prefix="$2"