# README

PSET

A modification of the BIP-174 standard for Partial Signed Elements Transaction.

Changes from the standard reference

This package is designed in order to apply the possible fewer changes to the reference spec so that it can be used for Elements unblinded and blinded transactions.

Essentially this version of partial transaction uses an underlying Elements unsigned transaction instead of a Bitcoin one, and the partial input WitnessUtxo field represents an Elements output rather than a Bitcoin one.

NOTE: The Elements implementation of PSET is under development at the moment (take a look here) and this package will likely change in the future to adapt to this standard.

Creator

The creator is an exported factory function named simply New with the following signature:

func New(inputs []*transaction.TxInput, outputs []*transaction.TxOutput, version int32, nLockTime uint32) (*Pset, error) {}

The role of this function is to simply create an unsigned partial transaction wiwht the given inputs, outputs, version and locktime.
The unblinded asset and amounts of the outputs are encoded into the "unsigned tx" field of the partial transaction.

Updater

The updater, as the name suggests, has the responsibility of updating the fields of any partial input or output. It consists of a collection of methods that, basically, has the purpose of adding any new field to an existing partial input (included issuance or reissuance placed in the unsigned tx) or output.
It also allows to add new inputs or outputs to the underlying unsigned transaction.

The updater can be instantiated by calling the NewUpdater factory function passing a partial transasction object.

Blinder

At the moment the blinder role is designed to blind ALL the outputs of the partial transaction, but this will change soon, letting one to blind only the set of outputs he wants.
Also, this version of the blinder requires that all the private keys necessary to unblind all the confidential inputs used must be provided.
Given this, the pset package is not useful in case multiple parties want to create a transaction by joining their inputs/outputs since they would need to reveal their blinding private keys and share them with the one encharged of assuming the blinder role.
The pset package will change in the future to support the use case mentioned before, but this is not yet planned in the development.

Signer

The signer is in charge of checking that when adding a signature to an input of the pset, this is valid and that also the pset is correctly structured. Given that, this role is implemented as a function Sign of the *Updater type. This function accepts an input index, a signature, a public key, and one between a redeem or witness script and checks that the signature is valid against the given script and pubkey, along with setting the partial input's signature script to the one provided.

Finalizer

The finalizer takes a partial transaction and combines every input's PartialSignature into the final input's SignatureScript. After finalizing, the partial transaction is complete, and it's ready to be extracted from the Pset wrapper and broadcasted to the network. This role is accomplished by a Finalize function that accepts a *Pset instance and an input index, and performs the operations described above, returning an error if any occurs during the process. It previously checks that the provided partial transaction is valid in the sense that it's ready to be finalized; otherwise, an error is returned. A handy FinalizeAll that runs the above method for every input of the provided *Pset is also exported.

Extractor

The extractor is a simple Extract function expecting a finalized partial transaction that returns the final signed transaction by adding the signatures of the partial inputs to the underlying unsigned transaction.

# Functions

Extract takes a finalized pset.Pset and outputs a finalized transaction instance.
Finalize assumes that the provided pset.Pset struct has all partial signatures and redeem scripts/witness scripts already prepared for the specified input, and so removes all temporary data and replaces them with completed sigScript and witness fields, which are stored in key-types 07 and 08.
FinalizeAll finalizes all inputs of a partial elements transaction by calling the Finalize function for every partial input.
MaybeFinalize attempts to finalize the input at index inIndex in the PSET p, returning true with no error if it succeeds, OR if the input has already been finalized.
MaybeFinalizeAll attempts to finalize all inputs of the pset.Pset that are not already finalized, and returns an error if it fails to do so.
New on provision of an input and output 'skeleton' for the transaction, a new partially populated PSET.
NewBlinder is a factory function using a map to select outputs to blind.
NewPsbtOutput creates an instance of PsbtOutput; the three parameters redeemScript, witnessScript and Bip32Derivation are all allowed to be `nil`.
NewPsetFromBase64 returns a new Pset from a serialized pset in base64 encoding.
NewPsetFromHex returns a new Pset from serialized pset in hex encoiding.
NewPsetFromUnsignedTx creates a new Pset struct, without any signatures (i.e.
NewPsetInput creates an instance of PsbtInput given either a nonWitnessUtxo or a witnessUtxo.
NewUpdater returns a new instance of Updater, if the passed Psbt struct is in a valid form, else an error.a.
The creator is an exported factory function named simply New with the following signature: func New(inputs []*transaction.TxInput, outputs []*transaction.TxOutput, version int32, nLockTime uint32) (*Pset, error) {} The role of this function is to simply create an unsigned partial transaction with the given inputs, outputs, version and locktime.
The updater, as the name suggests, has the responsibility of updating the fields of any partial input or output.
At the moment the blinder role is designed to blind ALL the outputs of the partial transaction but this will change soon, letting one to blind only the set of outputs he wants.
The signer is in charge of checking that when adding a signature to an input of the pset, this is valid and that also the pset is correctly structured.
The finalizer takes a partial transaction and combines every input's PartialSignature into the final input's SignatureScript.
The extractor is a simple Extract function expecting a finalized partial transaction that returns the final signed transaction by adding the signatures of the partial inputs to the underlying unsigned transaction.
This is an exemplification on how to perform a P2WPKH transaction using the PSET package with the assistance of vulpemventures/nigiri for funding the address, retrieving the UTXOs and broadcasting.
VerifyBlinding verifies the proofs of all the confidential outputs of the given transaction, with the given in/out private blinding keys.

# Constants

No description provided by the author
No description provided by the author

# Variables

ErrGenerateSurjectionProof is returned if the computation of the surjection proof fails.
ErrNeedPrevout is returned if a BlindingDataLike needs the input's prevout but received nil.

# Structs

AddIssuanceArgs is a struct encapsulating all the issuance data that can be attached to any specific transaction of the PSBT.
AddReissuanceArgs defines the mandatory fields that one needs to pass to the AddReissuance method of the *Updater type PrevOutHash: the prevout hash of the token that will be added as input to the tx PrevOutIndex: the prevout index of the token that will be added as input to the tx PrevOutBlinder: the asset blinder used to blind the prevout token WitnessUtxo: the prevout token in case it is a witness one NonWitnessUtxo: the prevout tx that include the token output in case it is a non witness one Entropy: the entropy used to generate token and asset AssetAmount: the amount of asset to re-issue TokenAmount: the same unblinded amount of the prevout token AssetAddress: the destination address of the re-issuing asset TokenAddress: the destination address of the re-issuance token.
Blinder is designed to blind ALL the outputs of the partial transaction.
IssuanceBlindingPrivateKeys stores the AssetKey and TokenKey that will be used in the Blinder.
PInput is a struct encapsulating all the data that can be attached to any specific input of the PSBT.
POutput is a struct encapsulating all the data that can be attached to any specific output of the PSBT.
Pset is the actual psbt repreesntation.
Unknown is a struct encapsulating a key-value pair for which the key type is unknown by this package; these fields are allowed in both the 'Global' and the 'Input' section of a PSET.
Updater encapsulates the role 'Updater' as specified in BIP174; it accepts Psbt structs and has methods to add fields to the inputs and outputs.

# Interfaces

BlindingDataLike defines data used to get blinders from input.

# Type aliases

BlindingData = blinders.
PrivateBlindingKey = a bytes slice | used on confidential input.
This type is for GoDoc documentation purposes only.