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

main.go

TEXT FILE

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

Download / RawBack to folder
Go · 59 lines
1package main
2
3import (
4	"crypto/rand"
5	"crypto/sha256"
6	"encoding/hex"
7	"encoding/json"
8	"os"
9	"strconv"
10
11	"github.com/btcsuite/btcd/btcec/v2"
12	htlc "wab-testnet3-htlc"
13)
14
15func main() {
16	height, err := strconv.ParseInt(os.Args[2], 10, 64)
17	if err != nil {
18		panic(err)
19	}
20	claim, err := btcec.NewPrivateKey()
21	if err != nil {
22		panic(err)
23	}
24	refund, err := btcec.NewPrivateKey()
25	if err != nil {
26		panic(err)
27	}
28	var secret [32]byte
29	if _, err := rand.Read(secret[:]); err != nil {
30		panic(err)
31	}
32	hash := sha256.Sum256(secret[:])
33	script, err := htlc.Script(hash, claim.PubKey().SerializeCompressed(), refund.PubKey().SerializeCompressed(), height)
34	if err != nil {
35		panic(err)
36	}
37	address, err := htlc.Testnet3Address(script)
38	if err != nil {
39		panic(err)
40	}
41	state, err := os.OpenFile(os.Args[1], os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600)
42	if err != nil {
43		panic(err)
44	}
45	if err := json.NewEncoder(state).Encode(map[string]string{
46		"secret": hex.EncodeToString(secret[:]), "claim": hex.EncodeToString(claim.Serialize()),
47		"refund": hex.EncodeToString(refund.Serialize()),
48	}); err != nil {
49		panic(err)
50	}
51	if err := state.Close(); err != nil {
52		panic(err)
53	}
54	if err := json.NewEncoder(os.Stdout).Encode(map[string]any{
55		"address": address.String(), "script": hex.EncodeToString(script), "hash": hex.EncodeToString(hash[:]), "refund_height": height,
56	}); err != nil {
57		panic(err)
58	}
59}
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