Files
ark/common/bitcointree/psbt.go
Louis Singer 01297ae38c Add support for covenant-less ASP (#214)
* scaffolding wallet

* remove wallet db, add loader instead

* wip

* implement some wallet methods

* signing and utxos

* renaming

* fee estimator

* chain source options

* config

* application service

* clark docker-compose

* CLI refactor

* v0 clark

* v0.1 clark

* fix SignTapscriptInput (btcwallet)

* wallet.Broadcast, send via explora

* fix ASP pubkey

* Use lnd's btcwallet & Add rpc to get wallet staus

* wip

* unilateral exit

* Fixes on watching for notifications and cli init

* handle non-final BIP68 errors

* Fixes

* Fixes

* Fix

* a

* fix onboard cosigners + revert tree validation

* fix covenant e2e tests

* fix covenantless e2e tests

* fix container naming

* fix lint error

* update REAME.md

* Add env var for wallet password

---------

Co-authored-by: altafan <18440657+altafan@users.noreply.github.com>
2024-07-30 20:57:52 +02:00

60 lines
1.2 KiB
Go

package bitcointree
import (
"bytes"
"github.com/btcsuite/btcd/btcutil/psbt"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
)
var (
COSIGNER_PSBT_KEY_PREFIX = []byte("cosigner")
)
func AddCosignerKey(inIndex int, ptx *psbt.Packet, key *secp256k1.PublicKey) error {
currentCosigners, err := GetCosignerKeys(ptx.Inputs[inIndex])
if err != nil {
return err
}
nextCosignerIndex := len(currentCosigners)
ptx.Inputs[inIndex].Unknowns = append(ptx.Inputs[inIndex].Unknowns, &psbt.Unknown{
Value: key.SerializeCompressed(),
Key: cosignerPrefixedKey(nextCosignerIndex),
})
return nil
}
func GetCosignerKeys(in psbt.PInput) ([]*secp256k1.PublicKey, error) {
var keys []*secp256k1.PublicKey
for _, u := range in.Unknowns {
cosignerIndex := parsePrefixedCosignerKey(u.Key)
if cosignerIndex == -1 {
continue
}
key, err := secp256k1.ParsePubKey(u.Value)
if err != nil {
return nil, err
}
keys = append(keys, key)
}
return keys, nil
}
func cosignerPrefixedKey(index int) []byte {
return append(COSIGNER_PSBT_KEY_PREFIX, byte(index))
}
func parsePrefixedCosignerKey(key []byte) int {
if !bytes.HasPrefix(key, COSIGNER_PSBT_KEY_PREFIX) {
return -1
}
return int(key[len(COSIGNER_PSBT_KEY_PREFIX)])
}