address

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 29 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// MainnetHRP is the HRP for mainnet.
	MainnetHRP = "tapbc"

	// TestnetHRP is the HRP for testnet.
	TestnetHRP = "taptb"

	// RegTestHRP is the HRP for regtest.
	RegTestHRP = "taprt"

	// SigNetHRP is the HRP for "the" signet.
	SigNetHRP = "taptb"

	// SimNetHRP is the HRP for simnet.
	SimNetHRP = "tapsb"
)
View Source
const Subsystem = "ADDR"

Subsystem defines the logging code for this subsystem.

Variables

View Source
var (
	// ErrUnsupportedHRP is an error returned when we attempt to encode a
	// Taproot Asset address with an HRP for a network without Taproot Asset
	// support.
	ErrUnsupportedHRP = errors.New("address: unsupported HRP value")

	// ErrMismatchedHRP is an error returned when we attempt to decode a
	// Taproot Asset address with an HRP that does not match the expected
	// network.
	ErrMismatchedHRP = errors.New("address: network mismatch")

	// ErrInvalidBech32m is an error returned when we attempt to decode a
	// Taproot Asset address from a string that is not a valid bech32m
	// string.
	ErrInvalidBech32m = errors.New("address: invalid bech32m string")

	// ErrInvalidAmountCollectible is an error returned when we attempt to
	// create a Taproot Asset address for a Collectible asset with an amount
	// not equal to one.
	ErrInvalidAmountCollectible = errors.New(
		"address: collectible asset amount not one",
	)

	// ErrInvalidAmountNormal is an error returned when we attempt to
	// create a Taproot Asset address for a Normal asset with an amount of
	// zero.
	ErrInvalidAmountNormal = errors.New(
		"address: normal asset amount of zero",
	)

	// ErrUnsupportedAssetType is an error returned when we attempt to
	// create a Taproot Asset address for a non-standard asset type.
	ErrUnsupportedAssetType = errors.New("address: unsupported asset type")

	// ErrNoAddr is returned if no address is found in the address store.
	ErrNoAddr = errors.New("address: no address found")

	// ErrNoEvent is returned if no event is found in the event store.
	ErrNoEvent = errors.New("address: no event found")

	// ErrScriptKeyNotFound is returned when a script key is not found in
	// the local database.
	ErrScriptKeyNotFound = errors.New("script key not found")

	// ErrInternalKeyNotFound is returned when an internal key is not found
	// in the local database.
	ErrInternalKeyNotFound = errors.New("internal key not found")

	// ErrUnknownVersion is returned when encountering an address with an
	// unrecognised version number.
	ErrUnknownVersion = errors.New("address: unknown version number")
)
View Source
var (
	// ErrAssetGroupUnknown is returned when the asset genesis is not known.
	// This means an address can't be created until a Universe bootstrap or
	// manual issuance proof insertion.
	ErrAssetGroupUnknown = fmt.Errorf("asset group is unknown")

	// ErrAssetMetaNotFound is returned when an asset meta is not found in
	// the database.
	ErrAssetMetaNotFound = fmt.Errorf("asset meta not found")
)
View Source
var (

	// MainNetTap holds the chain params for mainnet.
	MainNetTap = ChainParams{
		Params: &chaincfg.MainNetParams,
		TapHRP: MainnetHRP,
	}

	// TestNet3Tap holds the chain params for testnet.
	TestNet3Tap = ChainParams{
		Params: &chaincfg.TestNet3Params,
		TapHRP: TestnetHRP,
	}

	// RegressionNetTap holds the chain params for regtest.
	RegressionNetTap = ChainParams{
		Params: &chaincfg.RegressionNetParams,
		TapHRP: RegTestHRP,
	}

	// SigNetTap holds the chain params for signet.
	SigNetTap = ChainParams{
		Params: &chaincfg.SigNetParams,
		TapHRP: SigNetHRP,
	}

	// SimNetTap holds the chain params for simnet.
	SimNetTap = ChainParams{
		Params: &chaincfg.SimNetParams,
		TapHRP: SimNetHRP,
	}
)
View Source
var KnownAddressTypes = fn.NewSet(
	addrVersionType, addrAssetVersionType, addrAssetIDType,
	addrGroupKeyType, addrScriptKeyType, addrInternalKeyType,
	addrTapscriptSiblingType, addrAmountType, addrProofCourierAddrType,
)

KnownAddressTypes is a set of all known address TLV types. This set is asserted to be complete by a check in the BIP test vector unit tests.

Functions

func CommitmentVersion added in v0.4.0

func CommitmentVersion(vers Version) (*commitment.TapCommitmentVersion,
	error)

CommitmentVersion returns the Taproot Asset commitment version that matches the address version.

func DisableLog added in v0.3.1

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func IsBech32MTapPrefix

func IsBech32MTapPrefix(prefix string) bool

IsBech32MTapPrefix returns whether the prefix is a known prefix for Taproot Asset addresses on any supported network. This is used when creating an address, encoding an address to a string, or decoding an address string into a TLV.

func IsForNet

func IsForNet(hrp string, net *ChainParams) bool

IsForNet returns whether the HRP is associated with the passed network.

func IsUnknownVersion added in v0.3.0

func IsUnknownVersion(v Version) bool

IsUnknownVersion returns true if the address version is not recognized by this implementation of tap.

func MarshalVersion added in v0.5.0

func MarshalVersion(version Version) (taprpc.AddrVersion, error)

MarshalVersion marshals the native address version into the RPC variant.

func RandProofCourierAddr added in v0.3.0

func RandProofCourierAddr(t testing.TB) url.URL

RandProofCourierAddr returns a proof courier address with fields populated with valid but random values.

func Register

func Register(params *ChainParams) error

Register attempts to register a new Taproot Asset ChainParams with the library. If a set of parameters for the network has already been registered, then an error is returned.

TODO(jhb): Resolve duplicate networks?

func UrlDecoder added in v0.4.0

func UrlDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error

UrlDecoder decodes a variable length byte slice as an url.URL.

func UrlEncoder added in v0.4.0

func UrlEncoder(w io.Writer, val any, buf *[8]byte) error

UrlEncoder encodes a url.URL as a variable length byte slice.

func UseLogger added in v0.3.1

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

func VersionDecoder added in v0.3.0

func VersionDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error

func VersionEncoder added in v0.3.0

func VersionEncoder(w io.Writer, val any, buf *[8]byte) error

Types

type AddrWithKeyInfo

type AddrWithKeyInfo struct {
	*Tap

	// ScriptKeyTweak houses the wallet specific information related to a
	// tweak key. This includes the raw key desc information along with the
	// tweak used to create the address.
	ScriptKeyTweak asset.TweakedScriptKey

	// InternalKeyDesc is the key desc for the internal key.
	InternalKeyDesc keychain.KeyDescriptor

	// TaprootOutputKey is the tweaked taproot output key that assets must
	// be sent to on chain to be received.
	TaprootOutputKey btcec.PublicKey

	// CreationTime is the time the address was created in the database.
	CreationTime time.Time

	// ManagedAfter is the time at which the address was imported into the
	// wallet.
	ManagedAfter time.Time
}

AddrWithKeyInfo wraps a normal Taproot Asset struct with key descriptor information.

func RandAddr

func RandAddr(t testing.TB, params *ChainParams,
	proofCourierAddr url.URL) (*AddrWithKeyInfo,
	*asset.Genesis, *asset.GroupKey)

RandAddr creates a random address for testing.

type AssetSyncer added in v0.3.1

type AssetSyncer interface {
	// SyncAssetInfo queries the universes in our federation for genesis
	// and asset group information about the given asset ID.
	SyncAssetInfo(ctx context.Context, assetID *asset.ID) error

	// EnableAssetSync updates the sync config for the given asset so that
	// we sync future issuance proofs.
	EnableAssetSync(ctx context.Context, groupInfo *asset.AssetGroup) error
}

AssetSyncer is an interface that allows the address.Book to look up asset genesis and group information from both the local asset store and assets known to universe servers in our federation.

type Book

type Book struct {
	// contains filtered or unexported fields
}

Book is used to create and also look up the set of created Taproot Asset addresses.

func NewBook

func NewBook(cfg BookConfig) *Book

NewBook creates a new Book instance from the config.

func (*Book) AddrByTaprootOutput

func (b *Book) AddrByTaprootOutput(ctx context.Context,
	key *btcec.PublicKey) (*AddrWithKeyInfo, error)

AddrByTaprootOutput returns a single address based on its Taproot output key or a sql.ErrNoRows error if no such address exists.

func (*Book) CompleteEvent

func (b *Book) CompleteEvent(ctx context.Context, event *Event,
	status Status, anchorPoint wire.OutPoint) error

CompleteEvent updates an address event as being complete and links it with the proof and asset that was imported/created for it.

func (*Book) FetchAssetMetaByHash added in v0.5.0

func (b *Book) FetchAssetMetaByHash(ctx context.Context,
	metaHash [asset.MetaHashLen]byte) (*proof.MetaReveal, error)

FetchAssetMetaByHash attempts to fetch an asset meta based on an asset hash.

func (*Book) FetchAssetMetaForAsset added in v0.5.0

func (b *Book) FetchAssetMetaForAsset(ctx context.Context,
	assetID asset.ID) (*proof.MetaReveal, error)

FetchAssetMetaForAsset attempts to fetch an asset meta based on an asset ID.

func (*Book) GetOrCreateEvent

func (b *Book) GetOrCreateEvent(ctx context.Context, status Status,
	addr *AddrWithKeyInfo, walletTx *lndclient.Transaction,
	outputIdx uint32) (*Event, error)

GetOrCreateEvent creates a new address event for the given status, address and transaction. If an event for that address and transaction already exists, then the status and transaction information is updated instead.

func (*Book) GetPendingEvents

func (b *Book) GetPendingEvents(ctx context.Context) ([]*Event, error)

GetPendingEvents returns all events that are not yet in status complete from the database.

func (*Book) InsertScriptKey added in v0.4.0

func (b *Book) InsertScriptKey(ctx context.Context, scriptKey asset.ScriptKey,
	declareAsKnown bool) error

InsertScriptKey inserts an address related script key into the database.

func (*Book) IsLocalKey

func (b *Book) IsLocalKey(ctx context.Context,
	key keychain.KeyDescriptor) bool

IsLocalKey returns true if the key is under the control of the wallet and can be derived by it.

func (*Book) ListAddrs

func (b *Book) ListAddrs(ctx context.Context,
	params QueryParams) ([]AddrWithKeyInfo, error)

ListAddrs lists a set of addresses based on the expressed query params.

func (*Book) NewAddress

func (b *Book) NewAddress(ctx context.Context, addrVersion Version,
	assetID asset.ID, amount uint64,
	tapscriptSibling *commitment.TapscriptPreimage,
	proofCourierAddr url.URL, addrOpts ...NewAddrOpt) (*AddrWithKeyInfo,
	error)

NewAddress creates a new Taproot Asset address based on the input parameters.

func (*Book) NewAddressWithKeys

func (b *Book) NewAddressWithKeys(ctx context.Context, addrVersion Version,
	assetID asset.ID, amount uint64, scriptKey asset.ScriptKey,
	internalKeyDesc keychain.KeyDescriptor,
	tapscriptSibling *commitment.TapscriptPreimage,
	proofCourierAddr url.URL, addrOpts ...NewAddrOpt) (*AddrWithKeyInfo,
	error)

NewAddressWithKeys creates a new Taproot Asset address based on the input parameters that include pre-derived script and internal keys.

func (*Book) NextInternalKey

func (b *Book) NextInternalKey(ctx context.Context,
	family keychain.KeyFamily) (keychain.KeyDescriptor, error)

NextInternalKey derives then inserts an internal key into the database to make sure it is identified as a local key later on when importing proofs. The key can be an internal key for an asset script key or the internal key of an anchor output.

func (*Book) NextScriptKey

func (b *Book) NextScriptKey(ctx context.Context,
	family keychain.KeyFamily) (asset.ScriptKey, error)

NextScriptKey derives then inserts a script key into the database to make sure it is identified as a local key later on when importing proofs.

func (*Book) QueryAssetInfo added in v0.4.0

func (b *Book) QueryAssetInfo(ctx context.Context,
	id asset.ID) (*asset.AssetGroup, error)

QueryAssetInfo attempts to locate asset genesis information by querying geneses already known to this node. If asset issuance was not previously verified, we then query universes in our federation for issuance proofs.

func (*Book) QueryEvent added in v0.4.0

func (b *Book) QueryEvent(ctx context.Context,
	addr *AddrWithKeyInfo, outpoint wire.OutPoint) (*Event, error)

QueryEvent returns a single address event by its address and outpoint.

func (*Book) QueryEvents

func (b *Book) QueryEvents(ctx context.Context,
	query EventQueryParams) ([]*Event, error)

QueryEvents returns all events that match the given query.

func (*Book) RegisterSubscriber

func (b *Book) RegisterSubscriber(
	receiver *fn.EventReceiver[*AddrWithKeyInfo],
	deliverExisting bool, deliverFrom QueryParams) error

RegisterSubscriber adds a new subscriber for receiving events. The deliverExisting boolean indicates whether already existing items should be sent to the NewItemCreated channel when the subscription is started. An optional deliverFrom can be specified to indicate from which timestamp/index/ marker onward existing items should be delivered on startup. If deliverFrom is nil/zero/empty then all existing items will be delivered.

func (*Book) RemoveSubscriber

func (b *Book) RemoveSubscriber(
	subscriber *fn.EventReceiver[*AddrWithKeyInfo]) error

RemoveSubscriber removes the given subscriber and also stops it from processing events.

func (*Book) SetAddrManaged

func (b *Book) SetAddrManaged(ctx context.Context, addr *AddrWithKeyInfo,
	managedFrom time.Time) error

SetAddrManaged sets an address as being managed by the internal wallet.

type BookConfig

type BookConfig struct {
	// Store holds the set of created addresses.
	Store Storage

	// Syncer allows the address.Book to sync issuance information for
	// assets from universe servers in our federation.
	Syncer AssetSyncer

	// KeyRing points to an active key ring instance.
	KeyRing KeyRing

	// Chain points to the chain the address.Book is active on.
	Chain ChainParams

	// StoreTimeout is the default timeout to use for any storage
	// interaction.
	StoreTimeout time.Duration
}

BookConfig is the main config for the address.Book.

type ChainParams

type ChainParams struct {
	*chaincfg.Params

	// TapHRP is the HRP to use for Taproot Asset addresses for the target
	// network.
	TapHRP string
}

ChainParams defines a Taproot Asset supporting network by its parameters. These parameters include those specified by chaincfg.Params, as well as a Taproot Asset specific HRP used for Taproot Asset addresses. These parameters may be used by Taproot Asset applications to differentiate networks as well as addresses and keys for one network from those intended for use on another network.

func Net

func Net(hrp string) (*ChainParams, error)

Net returns the ChainParams struct associated with a Taproot Asset HRP.

func ParamsForChain

func ParamsForChain(name string) ChainParams

ParamsForChain returns the ChainParams for a given chain based on its name.

type ErrorTestCase added in v0.3.0

type ErrorTestCase struct {
	Address *TestAddress `json:"address"`
	Error   string       `json:"error"`
	Comment string       `json:"comment"`
}

type Event

type Event struct {
	// ID is the database primary key ID of the address event.
	ID int64

	// CreationTime is the time the event was first created.
	CreationTime time.Time

	// Addr is the Taproot Asset address that was used to receive the
	// assets.
	Addr *AddrWithKeyInfo

	// Status represents the current status of the incoming assets.
	Status Status

	// Outpoint is the on-chain transaction outpoint that contains the
	// Taproot Asset commitment for the incoming asset transfer.
	Outpoint wire.OutPoint

	// Amt is the amount of satoshis that were transferred in the Bitcoin
	// on-chain transaction. This is independent of the asset amount, which
	// can be looked up through the Addr field.
	Amt btcutil.Amount

	// InternalKey is the key used as the internal key for the on-chain
	// Taproot output. The internal key tweaked with the Taproot Asset
	// commitment (when NO tapscript sibling if present) is equal to the
	// TaprootOutputKey of the Addr.
	InternalKey *btcec.PublicKey

	// ConfirmationHeight is the block height at which the incoming asset
	// transfer transaction was first confirmed.
	ConfirmationHeight uint32

	// HasProof indicates that a proof for this transfer was imported. We
	// don't keep a reference to it in memory as the proof itself can be
	// large. The proof can be fetched by the script key of the address.
	HasProof bool
}

Event represents a single incoming asset transfer that was initiated by sending an on-chain transaction to the Taproot output key generated by a Taproot Asset address. Each event represents a single on-chain UTXO that is being taken custody of and is being tracked/watched by the internal wallet. One Taproot Asset address can receive multiple times and therefore can have multiple events.

type EventQueryParams

type EventQueryParams struct {
	// AddrTaprootOutputKey is the optional 32-byte x-only serialized
	// Taproot output key of the address to filter by. Must be set to nil
	// to return events for all addresses.
	AddrTaprootOutputKey []byte

	// StatusFrom is the smallest status to query for (inclusive). Can be
	// set to nil to return events of all states.
	StatusFrom *Status

	// StatusTo is the largest status to query for (inclusive). Can be
	// set to nil to return events of all states.
	StatusTo *Status

	// CreationTimeFrom is the earliest creation time to query for
	// (inclusive). Can be set to nil to return events of all creation
	// times.
	CreationTimeFrom *time.Time
}

EventQueryParams holds the set of query params for address events.

type EventStorage

type EventStorage interface {
	// GetOrCreateEvent creates a new address event for the given status,
	// address and transaction. If an event for that address and transaction
	// already exists, then the status and transaction information is
	// updated instead.
	GetOrCreateEvent(ctx context.Context, status Status,
		addr *AddrWithKeyInfo, walletTx *lndclient.Transaction,
		outputIdx uint32) (*Event, error)

	// QueryAddrEvents returns a list of event that match the given query
	// parameters.
	QueryAddrEvents(ctx context.Context, params EventQueryParams) ([]*Event,
		error)

	// QueryEvent returns a single address event by its address and
	// outpoint.
	QueryEvent(ctx context.Context, addr *AddrWithKeyInfo,
		outpoint wire.OutPoint) (*Event, error)

	// CompleteEvent updates an address event as being complete and links it
	// with the proof and asset that was imported/created for it.
	CompleteEvent(ctx context.Context, event *Event, status Status,
		anchorPoint wire.OutPoint) error
}

EventStorage is the interface that a component storing address events should implement.

type KeyRing

type KeyRing interface {
	// DeriveNextTaprootAssetKey attempts to derive the *next* key within
	// the TaprootAsset key family.
	DeriveNextTaprootAssetKey(context.Context) (keychain.KeyDescriptor,
		error)

	// DeriveNextKey attempts to derive the *next* key within the key
	// family (account in BIP43) specified. This method should return the
	// next external child within this branch.
	DeriveNextKey(context.Context,
		keychain.KeyFamily) (keychain.KeyDescriptor, error)

	// IsLocalKey returns true if the key is under the control of the wallet
	// and can be derived by it.
	IsLocalKey(ctx context.Context, desc keychain.KeyDescriptor) bool
}

KeyRing is used to create script and internal keys for Taproot Asset addresses.

type NewAddrOpt added in v0.3.0

type NewAddrOpt func(*newAddrOptions)

NewAddrOpt is a functional option that allows callers to modify how a new address will be created.

func WithAssetVersion added in v0.3.0

func WithAssetVersion(v asset.Version) NewAddrOpt

WithAssetVersion is a new address option that allows callers to specify the version of the asset version in the address.

type QueryParams

type QueryParams struct {
	// CreatedAfter if set, only addresses created after the time will be
	// returned.
	CreatedAfter time.Time

	// CreatedBefore is set, only the addresses created before the time
	// will be returned.
	CreatedBefore time.Time

	// Limit if set, only this many addresses will be returned.
	Limit int32

	// Offset if set, then the final result will be offset by this many
	// addresses.
	Offset int32

	// UnmanagedOnly is a boolean pointer indicating whether only addresses
	// should be returned that are not yet managed by the wallet.
	UnmanagedOnly bool
}

QueryParams holds the set of query params for the address book.

type Status

type Status uint8

Status denotes an address event's current status.

const (
	// StatusTransactionDetected denotes that a transaction for an incoming
	// asset transfer was detected but the transaction hasn't been confirmed
	// yet.
	StatusTransactionDetected Status = 0

	// StatusTransactionConfirmed denotes that the transaction for an
	// incoming asset transfer was confirmed. The transfer now requires the
	// proof to be imported to proceed.
	StatusTransactionConfirmed Status = 1

	// StatusProofReceived denotes that the proof for an incoming asset
	// transfer was received and is now being validated and processed.
	StatusProofReceived Status = 2

	// StatusCompleted denotes that an incoming asset transfer was completed
	// successfully and the local node has taken over custody of the assets
	// that were transferred.
	StatusCompleted Status = 3
)

type Storage

type Storage interface {
	EventStorage

	// InsertAddrs inserts a series of addresses into the database.
	InsertAddrs(ctx context.Context, addrs ...AddrWithKeyInfo) error

	// QueryAddrs attempts to query for a set of addresses.
	QueryAddrs(ctx context.Context,
		params QueryParams) ([]AddrWithKeyInfo, error)

	// QueryAssetGroup attempts to locate the asset group information
	// (genesis + group key) associated with a given asset.
	QueryAssetGroup(context.Context, asset.ID) (*asset.AssetGroup, error)

	// FetchAssetMetaByHash attempts to fetch an asset meta based on an
	// asset hash.
	FetchAssetMetaByHash(ctx context.Context,
		metaHash [asset.MetaHashLen]byte) (*proof.MetaReveal, error)

	// FetchAssetMetaForAsset attempts to fetch an asset meta based on an
	// asset ID.
	FetchAssetMetaForAsset(ctx context.Context,
		assetID asset.ID) (*proof.MetaReveal, error)

	// AddrByTaprootOutput returns a single address based on its Taproot
	// output key or a sql.ErrNoRows error if no such address exists.
	AddrByTaprootOutput(ctx context.Context,
		key *btcec.PublicKey) (*AddrWithKeyInfo, error)

	// SetAddrManaged sets an address as being managed by the internal
	// wallet.
	SetAddrManaged(ctx context.Context, addr *AddrWithKeyInfo,
		managedFrom time.Time) error

	// InsertInternalKey inserts an internal key into the database to make
	// sure it is identified as a local key later on when importing proofs.
	// The key can be an internal key for an asset script key or the
	// internal key of an anchor output.
	InsertInternalKey(ctx context.Context,
		keyDesc keychain.KeyDescriptor) error

	// InsertScriptKey inserts an address related script key into the
	// database, so it can be recognized as belonging to the wallet when a
	// transfer comes in later on. The script key can be declared as known
	// if it contains an internal key that isn't derived by the backing
	// wallet (e.g. NUMS key) but it should still be recognized as a key
	// being relevant for the local wallet (e.g. show assets received on
	// this key in the asset list and balances).
	InsertScriptKey(ctx context.Context, scriptKey asset.ScriptKey,
		declareAsKnown bool) error
}

Storage is the main storage interface for the address book.

type Tap

type Tap struct {
	// Version is the version of the address.
	Version Version

	// ChainParams is the reference to the chain parameters that were used
	// to encode the Taproot Asset address.
	ChainParams *ChainParams

	// AssetVersion is the Taproot Asset version of the asset.
	AssetVersion asset.Version

	// AssetID is the asset ID of the asset.
	AssetID asset.ID

	// GroupKey is the tweaked public key that is used to associate assets
	// together across distinct asset IDs, allowing further issuance of the
	// asset to be made possible.
	GroupKey *btcec.PublicKey

	// ScriptKey represents a tweaked Taproot output key encumbering the
	// different ways an asset can be spent.
	ScriptKey btcec.PublicKey

	// InternalKey is the BIP-0340/0341 public key of the receiver.
	InternalKey btcec.PublicKey

	// TapscriptSibling is the tapscript sibling preimage of the script that
	// will be committed to alongside the assets received through this
	// address. This will usually be empty.
	TapscriptSibling *commitment.TapscriptPreimage

	// Amount is the number of asset units being requested by the receiver.
	Amount uint64

	// ProofCourierAddr is the address of the proof courier that will be
	// used to distribute related proofs for this address.
	ProofCourierAddr url.URL

	// UnknownOddTypes is a map of unknown odd types that were encountered
	// during decoding. This map is used to preserve unknown types that we
	// don't know of yet, so we can still encode them back when serializing.
	// This enables forward compatibility with future versions of the
	// protocol as it allows new odd (optional) types to be added without
	// breaking old clients that don't yet fully understand them.
	UnknownOddTypes tlv.TypeMap
	// contains filtered or unexported fields
}

Tap represents a Taproot Asset address. Taproot Asset addresses specify an asset, pubkey, and amount.

func DecodeAddress

func DecodeAddress(addr string, net *ChainParams) (*Tap, error)

DecodeAddress parses a bech32m encoded Taproot Asset address string and returns the HRP and address TLV.

func New

func New(version Version, genesis asset.Genesis, groupKey *btcec.PublicKey,
	groupWitness wire.TxWitness, scriptKey btcec.PublicKey,
	internalKey btcec.PublicKey, amt uint64,
	tapscriptSibling *commitment.TapscriptPreimage, net *ChainParams,
	proofCourierAddr url.URL, opts ...NewAddrOpt) (*Tap, error)

New creates an address for receiving a Taproot asset.

TODO(ffranr): This function takes many arguments. Add a struct to better organise its arguments.

func (*Tap) AssetCommitmentKey

func (a *Tap) AssetCommitmentKey() [32]byte

AssetCommitmentKey is the key that maps to the asset leaf for the asset specified by a Taproot Asset address.

func (*Tap) AssetType

func (a *Tap) AssetType() asset.Type

AssetType returns the type of asset that this address was generated for.

func (*Tap) AttachGenesis

func (a *Tap) AttachGenesis(gen asset.Genesis)

AttachGenesis attaches the asset's genesis metadata to the address.

func (*Tap) Copy

func (a *Tap) Copy() *Tap

Copy returns a deep copy of an Address.

func (*Tap) Decode

func (a *Tap) Decode(r io.Reader) error

Decode decodes an address from a TLV stream.

func (*Tap) DecodeRecords

func (a *Tap) DecodeRecords() []tlv.Record

DecodeRecords provides all records known for an address for proper decoding.

func (*Tap) Encode

func (a *Tap) Encode(w io.Writer) error

Encode encodes an address into a TLV stream.

func (*Tap) EncodeAddress

func (a *Tap) EncodeAddress() (string, error)

EncodeAddress returns a bech32m string encoding of a Taproot Asset address.

func (*Tap) EncodeRecords

func (a *Tap) EncodeRecords() []tlv.Record

EncodeRecords determines the non-nil records to include when encoding an address at runtime.

func (*Tap) Net

func (a *Tap) Net() (*ChainParams, error)

Net returns the ChainParams struct matching the Taproot Asset address network.

func (*Tap) String

func (a *Tap) String() string

String returns the string representation of a Taproot Asset address.

func (*Tap) TapCommitment

func (a *Tap) TapCommitment() (*commitment.TapCommitment, error)

TapCommitment constructs the Taproot Asset commitment that is expected to appear on chain when assets are being sent to this address.

func (*Tap) TapCommitmentKey

func (a *Tap) TapCommitmentKey() [32]byte

TapCommitmentKey is the key that maps to the root commitment for the asset group specified by a Taproot Asset address.

func (*Tap) TaprootOutputKey

func (a *Tap) TaprootOutputKey() (*btcec.PublicKey, error)

TaprootOutputKey returns the on-chain Taproot output key.

type TestAddress added in v0.3.0

type TestAddress struct {
	Version          uint8       `json:"version"`
	ChainParamsHRP   string      `json:"chain_params_hrp"`
	AssetVersion     uint8       `json:"asset_version"`
	AssetID          string      `json:"asset_id"`
	GroupKey         string      `json:"group_key"`
	ScriptKey        string      `json:"script_key"`
	InternalKey      string      `json:"internal_key"`
	TapscriptSibling string      `json:"tapscript_sibling"`
	Amount           uint64      `json:"amount"`
	ProofCourierAddr string      `json:"proof_courier_addr"`
	UnknownOddTypes  tlv.TypeMap `json:"unknown_odd_types"`
}

func NewTestFromAddress added in v0.3.0

func NewTestFromAddress(t testing.TB, a *Tap) *TestAddress

func (*TestAddress) ToAddress added in v0.3.0

func (ta *TestAddress) ToAddress(t testing.TB) *Tap

type TestVectors added in v0.3.0

type TestVectors struct {
	ValidTestCases []*ValidTestCase `json:"valid_test_cases"`
	ErrorTestCases []*ErrorTestCase `json:"error_test_cases"`
}

type ValidTestCase added in v0.3.0

type ValidTestCase struct {
	Address  *TestAddress `json:"address"`
	Expected string       `json:"expected"`
	Comment  string       `json:"comment"`
}

type Version added in v0.3.0

type Version uint8

Version denotes the version of a Taproot Asset address format.

const (
	// V0 is the initial Taproot Asset address format version.
	V0 Version = 0

	// V1 addresses use V2 Taproot Asset commitments.
	V1 Version = 1
)

func UnmarshalVersion added in v0.5.0

func UnmarshalVersion(version taprpc.AddrVersion) (Version, error)

UnmarshalVersion parses an address version from the RPC variant.

Jump to

Keyboard shortcuts

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