Update client sdk (#207)

* Add bitcoin networks

* Refactor client

* Refactor explorer

* Refactor store

* Refactor wallet

* Refactor sdk client

* Refactor wasm & Update examples

* Move common util funcs to internal/utils

* Move to constants for service types

* Add unit tests

* Parallelize tests

* Lint

* Add job to gh action

* go mod tidy

* Fixes

* Fixes

* Fix compose file

* Fixes

* Fixes after review:
* Drop factory pattern
* Drop password from ark client methods
* Make singlekey wallet manage store and wallet store instead of defining WalletStore as extension of Store
* Move constants to arksdk module
* Drop config and expect directory store and wallet as ark client factory args

* Fix

* Add constants for bitcoin/liquid explorer

* Fix test

* Fix wasm

* Rename client.Client to client.ASPClient

* Rename store.Store to store.ConfigStore

* Rename wallet.Wallet to wallet.WalletService

* Renamings

* Lint

* Fixes

* Move everything to internal/utils & move ComputeVtxoTaprootScript to common

* Go mod tidy
This commit is contained in:
Pietralberto Mazza
2024-07-30 16:08:23 +02:00
committed by GitHub
parent e45bff3c70
commit 89df461623
148 changed files with 8497 additions and 6466 deletions

View File

@@ -9,6 +9,9 @@ import (
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/txscript"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/vulpemventures/go-elements/address"
"github.com/vulpemventures/go-elements/network"
"github.com/vulpemventures/go-elements/payment"
"github.com/vulpemventures/go-elements/taproot"
)
@@ -60,7 +63,6 @@ func DecodeClosure(script []byte) (Closure, error) {
}
return nil, fmt.Errorf("invalid closure script")
}
func (f *ForfeitClosure) Leaf() (*taproot.TapElementsLeaf, error) {
@@ -281,6 +283,59 @@ func (c *UnrollClosure) Decode(script []byte) (valid bool, err error) {
return true, nil
}
func ComputeVtxoTaprootScript(
userPubkey, aspPubkey *secp256k1.PublicKey, exitDelay uint, net network.Network,
) (*secp256k1.PublicKey, *taproot.TapscriptElementsProof, []byte, string, error) {
redeemClosure := &CSVSigClosure{
Pubkey: userPubkey,
Seconds: exitDelay,
}
forfeitClosure := &ForfeitClosure{
Pubkey: userPubkey,
AspPubkey: aspPubkey,
}
redeemLeaf, err := redeemClosure.Leaf()
if err != nil {
return nil, nil, nil, "", err
}
forfeitLeaf, err := forfeitClosure.Leaf()
if err != nil {
return nil, nil, nil, "", err
}
vtxoTaprootTree := taproot.AssembleTaprootScriptTree(
*redeemLeaf, *forfeitLeaf,
)
root := vtxoTaprootTree.RootNode.TapHash()
unspendableKey := UnspendableKey()
vtxoTaprootKey := taproot.ComputeTaprootOutputKey(unspendableKey, root[:])
redeemLeafHash := redeemLeaf.TapHash()
proofIndex := vtxoTaprootTree.LeafProofIndex[redeemLeafHash]
proof := vtxoTaprootTree.LeafMerkleProofs[proofIndex]
pay, err := payment.FromTweakedKey(vtxoTaprootKey, &net, nil)
if err != nil {
return nil, nil, nil, "", err
}
addr, err := pay.TaprootAddress()
if err != nil {
return nil, nil, nil, "", err
}
script, err := address.ToOutputScript(addr)
if err != nil {
return nil, nil, nil, "", err
}
return vtxoTaprootKey, &proof, script, addr, nil
}
func decodeIntrospectionScript(
script []byte, expectedIndex byte, isVerify bool,
) (bool, *secp256k1.PublicKey, uint64, error) {