payment

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2020 License: MIT Imports: 10 Imported by: 10

Documentation

Overview

Package payment is an abstract for working with all kind of addresses in Liquid network.

It can be used for the creation of p2pkh, p2ms, p2sh, non-native SegWit and native SegWit addresses.

It also provides support for confidential payments.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash160 added in v0.0.4

func Hash160(buf []byte) []byte

Hash160 calculates the hash ripemd160(sha256(b)).

Types

type Payment

type Payment struct {
	Hash          []byte
	WitnessHash   []byte
	Script        []byte
	WitnessScript []byte
	Redeem        *Payment
	PublicKey     *btcec.PublicKey
	BlindingKey   *btcec.PublicKey
	Network       *network.Network
}

Payment defines the structure that holds the information different addresses

func FromPayment

func FromPayment(payment *Payment) (*Payment, error)

FromPayment creates a Payment struct from a another Payment

Example

This examples shows how nested payment can be done in order to create non native SegWit(P2SH-P2WPKH) address

package main

import (
	"encoding/hex"
	"fmt"

	"github.com/btcsuite/btcd/btcec"
	"github.com/vulpemventures/go-elements/network"
	"github.com/vulpemventures/go-elements/payment"
)

const privateKeyHex = "1cc080a4cd371eafcad489a29664af6a7276b362fe783443ce036552482b971d"

var privateKeyBytes, _ = hex.DecodeString(privateKeyHex)

func main() {
	_, publicKey := btcec.PrivKeyFromBytes(btcec.S256(), privateKeyBytes)
	p2wpkh := payment.FromPublicKey(publicKey, &network.Regtest, nil)
	pay, err := payment.FromPayment(p2wpkh)
	p2sh, err := pay.ScriptHash()
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("Non native SegWit address %v\n:", p2sh)
}
Output:

func FromPublicKey

func FromPublicKey(
	pubkey *btcec.PublicKey,
	net *network.Network,
	blindingKey *btcec.PublicKey,
) *Payment

FromPublicKey creates a Payment struct from a btcec.publicKey

Example

This examples shows how standard P2PKH address can be created

package main

import (
	"encoding/hex"
	"fmt"

	"github.com/btcsuite/btcd/btcec"
	"github.com/vulpemventures/go-elements/network"
	"github.com/vulpemventures/go-elements/payment"
)

const privateKeyHex = "1cc080a4cd371eafcad489a29664af6a7276b362fe783443ce036552482b971d"

var privateKeyBytes, _ = hex.DecodeString(privateKeyHex)

func main() {
	_, publicKey := btcec.PrivKeyFromBytes(btcec.S256(), privateKeyBytes)
	pay := payment.FromPublicKey(publicKey, &network.Regtest, nil)
	addr, _ := pay.PubKeyHash()
	fmt.Printf("P2PKH address %v\n:", addr)
}
Output:

func FromPublicKeys

func FromPublicKeys(
	pubkeys []*btcec.PublicKey,
	nrequired int,
	net *network.Network,
	blindingKey *btcec.PublicKey,
) (*Payment, error)

FromPublicKeys creates a multi-signature Payment struct from list of public key's

func FromScript

func FromScript(
	script []byte,
	net *network.Network,
	blindingKey *btcec.PublicKey,
) (*Payment, error)

FromScript creates parses a script into a Payment struct

func (*Payment) ConfidentialPubKeyHash added in v0.0.2

func (p *Payment) ConfidentialPubKeyHash() (string, error)

ConfidentialPubKeyHash is a method of the Payment struct to derive a base58 confidential p2pkh address

func (*Payment) ConfidentialScriptHash added in v0.0.2

func (p *Payment) ConfidentialScriptHash() (string, error)

ConfidentialScriptHash is a method of the Payment struct to derive a base58 confidential p2sh address

func (*Payment) ConfidentialWitnessPubKeyHash added in v0.0.2

func (p *Payment) ConfidentialWitnessPubKeyHash() (string, error)

ConfidentialWitnessPubKeyHash is a method of the Payment struct to derive a confidential blech32 p2wpkh address

func (*Payment) ConfidentialWitnessScriptHash added in v0.0.2

func (p *Payment) ConfidentialWitnessScriptHash() (string, error)

ConfidentialWitnessScriptHash is a method of the Payment struct to derive a confidential blech32 p2wsh address

func (*Payment) PubKeyHash

func (p *Payment) PubKeyHash() (string, error)

PubKeyHash is a method of the Payment struct to derive a base58 p2pkh address

func (*Payment) ScriptHash

func (p *Payment) ScriptHash() (string, error)

ScriptHash is a method of the Payment struct to derive a base58 p2sh address

func (*Payment) WitnessPubKeyHash

func (p *Payment) WitnessPubKeyHash() (string, error)

WitnessPubKeyHash is a method of the Payment struct to derive a base58 p2wpkh address

func (*Payment) WitnessScriptHash

func (p *Payment) WitnessScriptHash() (string, error)

WitnessScriptHash is a method of the Payment struct to derive a base58 p2wsh address

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL