Skip to content

Commit

Permalink
change mod name && added get private key from mnemonic and hdkey path…
Browse files Browse the repository at this point in the history
… example
  • Loading branch information
VincentDebug committed Dec 16, 2023
1 parent ad03d8b commit 6f2da42
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 11 deletions.
42 changes: 42 additions & 0 deletions examples/getprivatekeyfrommnemonicandhdkeypath/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"encoding/hex"
"fmt"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/hdkeychain"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript"
"github.com/tyler-smith/go-bip39"
"log"
)

func main() {
// random mnemonic 24 words
entropy, _ := bip39.NewEntropy(256)
randomMnemonic, _ := bip39.NewMnemonic(entropy)
fmt.Println(randomMnemonic)

mnemonic := randomMnemonic // "your mnemonic"
netParams := &chaincfg.MainNetParams // for generate address
rootKey, err := hdkeychain.NewMaster(bip39.NewSeed(mnemonic, ""), netParams)
if err != nil {
log.Fatal(err)
}

// 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"
childKey, _ := rootKey.Derive(hdkeychain.HardenedKeyStart + 86) // 86'
childKey, _ = childKey.Derive(hdkeychain.HardenedKeyStart + 0) // 0'
childKey, _ = childKey.Derive(hdkeychain.HardenedKeyStart + 0) // 0'
childKey, _ = childKey.Derive(1) // 1
senderKey, _ := childKey.Derive(0) // 0
senderPrivateKey, _ := senderKey.ECPrivKey()
privateKeyHex := hex.EncodeToString(senderPrivateKey.Serialize())
log.Printf("priviate key: %s \n", privateKeyHex)
taprootAddress, err := btcutil.NewAddressTaproot(schnorr.SerializePubKey(txscript.ComputeTaprootKeyNoScript(senderPrivateKey.PubKey())), netParams)
if err != nil {
log.Fatal(err)
}
log.Printf("taproot address: %s \n", taprootAddress.EncodeAddress())
}
4 changes: 2 additions & 2 deletions examples/inscribefile/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"go-ord-tx/internal/ord"
"go-ord-tx/pkg/btcapi/mempool"
"github.com/vincentdebug/go-ord-tx/internal/ord"
"github.com/vincentdebug/go-ord-tx/pkg/btcapi/mempool"
"log"
"net/http"
"os"
Expand Down
4 changes: 2 additions & 2 deletions examples/inscribewithoutnoderpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"go-ord-tx/internal/ord"
"go-ord-tx/pkg/btcapi/mempool"
"github.com/vincentdebug/go-ord-tx/internal/ord"
"github.com/vincentdebug/go-ord-tx/pkg/btcapi/mempool"
"log"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/inscribewithprivatenoderpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/wire"
"go-ord-tx/internal/ord"
"github.com/vincentdebug/go-ord-tx/internal/ord"
"log"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/inscribewithpublicnoderpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"go-ord-tx/internal/ord"
"github.com/vincentdebug/go-ord-tx/internal/ord"
"log"
)

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module go-ord-tx
module github.com/vincentdebug/go-ord-tx

go 1.20

Expand All @@ -8,6 +8,7 @@ require (
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2
github.com/pkg/errors v0.9.1
github.com/tyler-smith/go-bip39 v1.1.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand Down
4 changes: 2 additions & 2 deletions internal/ord/ord.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/pkg/errors"
"go-ord-tx/pkg/btcapi"
extRpcClient "go-ord-tx/pkg/rpcclient"
"github.com/vincentdebug/go-ord-tx/pkg/btcapi"
extRpcClient "github.com/vincentdebug/go-ord-tx/pkg/rpcclient"
"log"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/btcapi/mempool/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"go-ord-tx/pkg/btcapi"
"github.com/vincentdebug/go-ord-tx/pkg/btcapi"
"net/http"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/btcapi/mempool/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mempool
import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/wire"
"go-ord-tx/pkg/btcapi"
"github.com/vincentdebug/go-ord-tx/pkg/btcapi"
"io"
"log"
)
Expand Down

0 comments on commit 6f2da42

Please sign in to comment.