THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

htlc.go

TEXT FILE

1.0 KB · Public source code for developers, search crawlers and AI agents

Download / RawBack to folder
Go · 31 lines
1package htlc
2
3import (
4	"crypto/sha256"
5	"fmt"
6
7	"github.com/btcsuite/btcd/btcutil"
8	"github.com/btcsuite/btcd/chaincfg"
9	"github.com/btcsuite/btcd/txscript"
10)
11
12// Script uses a block-height refund lock and compressed public keys.
13func Script(hash [32]byte, claimKey, refundKey []byte, expiry int64) ([]byte, error) {
14	if expiry <= 0 || expiry >= 500000000 {
15		return nil, fmt.Errorf("expiry must be a block height")
16	}
17	return txscript.NewScriptBuilder().
18		AddOp(txscript.OP_IF).
19		AddOp(txscript.OP_SIZE).AddInt64(32).AddOp(txscript.OP_EQUALVERIFY).
20		AddOp(txscript.OP_SHA256).AddData(hash[:]).AddOp(txscript.OP_EQUALVERIFY).
21		AddData(claimKey).
22		AddOp(txscript.OP_ELSE).
23		AddInt64(expiry).AddOp(txscript.OP_CHECKLOCKTIMEVERIFY).AddOp(txscript.OP_DROP).
24		AddData(refundKey).
25		AddOp(txscript.OP_ENDIF).AddOp(txscript.OP_CHECKSIG).Script()
26}
27
28func Testnet3Address(script []byte) (*btcutil.AddressWitnessScriptHash, error) {
29	hash := sha256.Sum256(script)
30	return btcutil.NewAddressWitnessScriptHash(hash[:], &chaincfg.TestNet3Params)
31}
Read-only source · Select a line number to link directly · Raw download above

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects