Skip to content

Commit 6f2da42

Browse files
committed
change mod name && added get private key from mnemonic and hdkey path example
1 parent ad03d8b commit 6f2da42

File tree

10 files changed

+56
-11
lines changed

10 files changed

+56
-11
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import (
4+
"encoding/hex"
5+
"fmt"
6+
"github.com/btcsuite/btcd/btcec/v2/schnorr"
7+
"github.com/btcsuite/btcd/btcutil"
8+
"github.com/btcsuite/btcd/btcutil/hdkeychain"
9+
"github.com/btcsuite/btcd/chaincfg"
10+
"github.com/btcsuite/btcd/txscript"
11+
"github.com/tyler-smith/go-bip39"
12+
"log"
13+
)
14+
15+
func main() {
16+
// random mnemonic 24 words
17+
entropy, _ := bip39.NewEntropy(256)
18+
randomMnemonic, _ := bip39.NewMnemonic(entropy)
19+
fmt.Println(randomMnemonic)
20+
21+
mnemonic := randomMnemonic // "your mnemonic"
22+
netParams := &chaincfg.MainNetParams // for generate address
23+
rootKey, err := hdkeychain.NewMaster(bip39.NewSeed(mnemonic, ""), netParams)
24+
if err != nil {
25+
log.Fatal(err)
26+
}
27+
28+
// for sparrow wallet receive addresses a path is start "m/86'/0'/0'/0/0"; change addresses a path is start "m/86'/0'/0'/1/0"
29+
childKey, _ := rootKey.Derive(hdkeychain.HardenedKeyStart + 86) // 86'
30+
childKey, _ = childKey.Derive(hdkeychain.HardenedKeyStart + 0) // 0'
31+
childKey, _ = childKey.Derive(hdkeychain.HardenedKeyStart + 0) // 0'
32+
childKey, _ = childKey.Derive(1) // 1
33+
senderKey, _ := childKey.Derive(0) // 0
34+
senderPrivateKey, _ := senderKey.ECPrivKey()
35+
privateKeyHex := hex.EncodeToString(senderPrivateKey.Serialize())
36+
log.Printf("priviate key: %s \n", privateKeyHex)
37+
taprootAddress, err := btcutil.NewAddressTaproot(schnorr.SerializePubKey(txscript.ComputeTaprootKeyNoScript(senderPrivateKey.PubKey())), netParams)
38+
if err != nil {
39+
log.Fatal(err)
40+
}
41+
log.Printf("taproot address: %s \n", taprootAddress.EncodeAddress())
42+
}

examples/inscribefile/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/btcsuite/btcd/chaincfg"
1010
"github.com/btcsuite/btcd/txscript"
1111
"github.com/btcsuite/btcd/wire"
12-
"go-ord-tx/internal/ord"
13-
"go-ord-tx/pkg/btcapi/mempool"
12+
"github.com/vincentdebug/go-ord-tx/internal/ord"
13+
"github.com/vincentdebug/go-ord-tx/pkg/btcapi/mempool"
1414
"log"
1515
"net/http"
1616
"os"

examples/inscribewithoutnoderpc/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/btcsuite/btcd/chaincfg"
99
"github.com/btcsuite/btcd/txscript"
1010
"github.com/btcsuite/btcd/wire"
11-
"go-ord-tx/internal/ord"
12-
"go-ord-tx/pkg/btcapi/mempool"
11+
"github.com/vincentdebug/go-ord-tx/internal/ord"
12+
"github.com/vincentdebug/go-ord-tx/pkg/btcapi/mempool"
1313
"log"
1414
)
1515

examples/inscribewithprivatenoderpc/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/btcsuite/btcd/chaincfg/chainhash"
77
"github.com/btcsuite/btcd/rpcclient"
88
"github.com/btcsuite/btcd/wire"
9-
"go-ord-tx/internal/ord"
9+
"github.com/vincentdebug/go-ord-tx/internal/ord"
1010
"log"
1111
)
1212

examples/inscribewithpublicnoderpc/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/btcsuite/btcd/rpcclient"
1111
"github.com/btcsuite/btcd/txscript"
1212
"github.com/btcsuite/btcd/wire"
13-
"go-ord-tx/internal/ord"
13+
"github.com/vincentdebug/go-ord-tx/internal/ord"
1414
"log"
1515
)
1616

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module go-ord-tx
1+
module github.com/vincentdebug/go-ord-tx
22

33
go 1.20
44

@@ -8,6 +8,7 @@ require (
88
github.com/btcsuite/btcd/btcutil v1.1.3
99
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2
1010
github.com/pkg/errors v0.9.1
11+
github.com/tyler-smith/go-bip39 v1.1.0
1112
)
1213

1314
require (

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
7878
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
7979
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
8080
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
81+
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
82+
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
8183
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
8284
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
8385
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

internal/ord/ord.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"github.com/btcsuite/btcd/txscript"
1717
"github.com/btcsuite/btcd/wire"
1818
"github.com/pkg/errors"
19-
"go-ord-tx/pkg/btcapi"
20-
extRpcClient "go-ord-tx/pkg/rpcclient"
19+
"github.com/vincentdebug/go-ord-tx/pkg/btcapi"
20+
extRpcClient "github.com/vincentdebug/go-ord-tx/pkg/rpcclient"
2121
"log"
2222
)
2323

pkg/btcapi/mempool/addresses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/btcsuite/btcd/btcutil"
77
"github.com/btcsuite/btcd/chaincfg/chainhash"
88
"github.com/btcsuite/btcd/wire"
9-
"go-ord-tx/pkg/btcapi"
9+
"github.com/vincentdebug/go-ord-tx/pkg/btcapi"
1010
"net/http"
1111
)
1212

pkg/btcapi/mempool/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package mempool
33
import (
44
"github.com/btcsuite/btcd/chaincfg"
55
"github.com/btcsuite/btcd/wire"
6-
"go-ord-tx/pkg/btcapi"
6+
"github.com/vincentdebug/go-ord-tx/pkg/btcapi"
77
"io"
88
"log"
99
)

0 commit comments

Comments
 (0)