Skip to content

Instantly share code, notes, and snippets.

@kdmukai
kdmukai / nostr_delegation.py
Last active December 20, 2022 16:48
Trying (and failing) to reproduce Nostr NIP-26 delegation signature
"""
see: https://github.com/nostr-protocol/nips/blob/master/26.md
"""
import hashlib
from binascii import unhexlify
from embit import bip39
from embit.bip32 import HDKey
from embit.ec import PrivateKey
@kdmukai
kdmukai / wallet_basic.py
Created December 5, 2022 18:29
Snippet: edits to wallet_basic.py to accommodate new, lower maxfeerate default
# check if we can list zero value tx as available coins
# 1. create raw_tx
# 2. hex-changed one output to 0.0
# 3. sign and send
# 4. check if recipient (node0) can list the zero value tx
usp = self.nodes[1].listunspent(query_options={'minimumAmount': '49.998'})[0]
inputs = [{"txid": usp['txid'], "vout": usp['vout']}]
test_amount = Decimal("0.00001000") # this output amount will be zeroed and thereby added to the fee
fee = Decimal("0.00000400") # start with a modest fee so our final fee won't exceed default maxfeerate
outputs = {self.nodes[1].getnewaddress(): usp['amount'] - test_amount - fee, self.nodes[0].getnewaddress(): test_amount}
@kdmukai
kdmukai / generate_mnemonic_and_addr.py
Last active November 4, 2022 17:45
Generate a 12-word mnemonic and first receive addr
from embit import bip32, bip39, script
from embit.slip39 import secure_randint
from embit.wordlists.bip39 import WORDLIST
for i in range(0, 100):
mnemonic = []
for j in range(0, 11):
# note: `secure_randint` is inclusive of the end of the range
mnemonic.append(WORDLIST[secure_randint(0, 2047)])
mnemonic.append(WORDLIST[0])
@kdmukai
kdmukai / op_return.py
Last active June 13, 2023 00:24
Adding an OP_RETURN output to a psbt using `embit`
"""
dependency: pip install embit
"""
from embit import compact
from embit.psbt import PSBT, OutputScope
from embit.script import Script
class OPCODES:
OP_RETURN = 106
OP_PUSHDATA1 = 76
@kdmukai
kdmukai / test_compact_seedqr.py
Created August 14, 2022 01:56
Generating byte data for Compact SeedQR test vectors
import os
from embit import bip39
from embit.wordlists.bip39 import WORDLIST
from seedsigner.models.decode_qr import DecodeQR
from seedsigner.models.encode_qr import EncodeQR
from seedsigner.models.qr_type import QRType
from seedsigner.helpers.qr import QR
seed_bytes = b''
@kdmukai
kdmukai / test.py
Created July 4, 2022 14:56
MicroPython + embit timing test
help('modules')
# import machine
# print(f"Initial freq: {int(machine.freq() / 1e6)}MHz")
# machine.freq(int(240*1e6))
# print(f"Current freq: {int(machine.freq() / 1e6)}MHz")
# pin = machine.Pin(13, machine.Pin.OUT)
# pin.value(1)
import time
@kdmukai
kdmukai / README.md
Last active June 17, 2022 13:24
SeedSigner vs a compromised coordinator sending a change-stealing single sig psbt

Single sig change-stealing attack from a compromised coordinator

See the full video walkthrough on twitter.

The CORRECT psbt

Spending uxto from regtest: 3641312fc3e418804f1a0a88098b6bf8e3bdca13afd2f0633ca3166fc8533f17

Signing mnemonic: "smoke chimney announce candy glory tongue refuse fatigue cricket once consider beef treat urge wing deny gym robot tobacco adult problem priority wheat diagram"

@kdmukai
kdmukai / install_bitcoind_macos.md
Last active November 17, 2021 19:54
Install Bitcoin Core v22+ bitcoind on macOS

Install Bitcoin Core v22+ bitcoind on macOS

If you don't have wget installed:

brew install wget

Download binary and verification hashes

wget https://bitcoin.org/bin/bitcoin-core-22.0/bitcoin-22.0-osx64.tar.gz
@kdmukai
kdmukai / install_bitcoind_raspi.md
Last active November 14, 2021 20:31
Install Bitcoin Core v22+ bitcoind binary on a Raspberry Pi

Install Bitcoin Core v22+ bitcoind on a Raspberry Pi

Procedure has changed, starting with v22!

Download binary and verification hashes

wget https://bitcoin.org/bin/bitcoin-core-22.0/bitcoin-22.0-arm-linux-gnueabihf.tar.gz
wget https://bitcoin.org/bin/bitcoin-core-22.0/SHA256SUMS.asc
wget https://bitcoin.org/bin/bitcoin-core-22.0/SHA256SUMS
@kdmukai
kdmukai / bitcoin_diff.py
Last active April 30, 2020 00:25
Bitcoin price diff calculator based on YYYY-MM-dd purchased
"""
Usage: python3 bitcoin_diff.py 2017-06-28
outputs:
Price on 2017-06-28: $2584.56
Price on 2020-04-29: $8783.59
Difference: 239.85%
"""
import datetime
import json