pike

package
v1.0.0-beta.9 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package pike provides functionality to work with Pay-to-PubKey-Hash (P2PKH) scripts in a blockchain context.

P2PKH is a common type of Bitcoin transaction that locks funds to a specific public key hash, requiring the corresponding private key to produce a valid signature for spending the funds. This package offers utilities to create, decode, and validate P2PKH scripts.

The package includes: - Functions to generate P2PKH addresses from public keys. - Methods to construct P2PKH scriptPubKey and scriptSig scripts. - Utilities to decode and inspect P2PKH scripts and addresses. - Validation functions to ensure the integrity and correctness of P2PKH scripts.

This package is intended for developers working with Bitcoin or other cryptocurrencies that support P2PKH transactions. It abstracts the low-level details and provides a high-level interface for creating and handling P2PKH scripts.

Example (GenerateLockingScripts)
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/libsv/go-bk/bec"

	"github.com/bitcoin-sv/spv-wallet/engine/pike"
)

func main() {
	// Example sender's public key (replace with actual sender's public key)
	senderPublicKeyHex := "034252e5359a1de3b8ec08e6c29b80594e88fb47e6ae9ce65ee5a94f0d371d2cde"
	senderPublicKeyBytes, err := hex.DecodeString(senderPublicKeyHex)
	if err != nil {
		panic(err)
	}
	senderPubKey, err := bec.ParsePubKey(senderPublicKeyBytes, bec.S256())
	if err != nil {
		panic(err)
	}

	receiverPublicKeyHex := "027c1404c3ecb034053e6dd90bc68f7933284559c7d0763367584195a8796d9b0e"
	receiverPublicKeyBytes, err := hex.DecodeString(receiverPublicKeyHex)
	if err != nil {
		panic(err)
	}
	receiverPubKey, err := bec.ParsePubKey(receiverPublicKeyBytes, bec.S256())
	if err != nil {
		panic(err)
	}

	// Example usage of GenerateOutputsTemplate
	outputsTemplate, err := pike.GenerateOutputsTemplate(10000)
	if err != nil {
		panic(fmt.Errorf("Error generating outputs template - %w", err))
	}

	// Example usage of GenerateLockingScriptsFromTemplates
	lockingScripts, err := pike.GenerateLockingScriptsFromTemplates(outputsTemplate, senderPubKey, receiverPubKey, "reference")
	if err != nil {
		panic(fmt.Errorf("Error generating locking scripts - %w", err))
	}

	for _, script := range lockingScripts {
		fmt.Println("Locking Script:", script)
	}

}
Output:

Locking Script: 76a9147327490be831259f38b0f9ab019413e51d1b40c688ac

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateLockingScriptsFromTemplates

func GenerateLockingScriptsFromTemplates(outputsTemplate []*template.OutputTemplate, senderPubKey, receiverPubKey *bec.PublicKey, reference string) ([]string, error)

GenerateLockingScriptsFromTemplates converts Pike outputs templates to scripts

func GenerateOutputsTemplate

func GenerateOutputsTemplate(satoshis uint64) ([]*template.OutputTemplate, error)

GenerateOutputsTemplate creates a Pike output template

Types

This section is empty.

Jump to

Keyboard shortcuts

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