Documentation
¶
Index ¶
- Constants
- Variables
- func CommitmentVersion(vers Version) (*commitment.TapCommitmentVersion, error)
- func DisableLog()
- func IsBech32MTapPrefix(prefix string) bool
- func IsForNet(hrp string, net *ChainParams) bool
- func IsUnknownVersion(v Version) bool
- func MarshalVersion(version Version) (taprpc.AddrVersion, error)
- func RandProofCourierAddr(t testing.TB) url.URL
- func RandProofCourierAddrForVersion(t testing.TB, version Version) url.URL
- func Register(params *ChainParams) error
- func UseLogger(logger btclog.Logger)
- func VersionDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func VersionEncoder(w io.Writer, val any, buf *[8]byte) error
- type AddrWithKeyInfo
- func RandAddr(t testing.TB, params *ChainParams, proofCourierAddr url.URL) (*AddrWithKeyInfo, *asset.Genesis, *asset.GroupKey)
- func RandAddrWithVersion(t testing.TB, params *ChainParams, proofCourierAddr url.URL, ...) (*AddrWithKeyInfo, *asset.Genesis, *asset.GroupKey)
- func RandAddrWithVersionAndScriptKey(t testing.TB, params *ChainParams, proofCourierAddr url.URL, ...) (*AddrWithKeyInfo, *asset.Genesis, *asset.GroupKey)
- type AssetOutput
- type AssetSyncer
- type Book
- func (b *Book) AddrByScriptKeyAndVersion(ctx context.Context, scriptKey *btcec.PublicKey, version Version) (*AddrWithKeyInfo, error)
- func (b *Book) AddrByTaprootOutput(ctx context.Context, key *btcec.PublicKey) (*AddrWithKeyInfo, error)
- func (b *Book) CompleteEvent(ctx context.Context, event *Event, status Status, anchorPoint wire.OutPoint) error
- func (b *Book) DecDisplayForAssetID(ctx context.Context, id asset.ID) (fn.Option[uint32], error)
- func (b *Book) FetchAssetMetaByHash(ctx context.Context, metaHash [asset.MetaHashLen]byte) (*proof.MetaReveal, error)
- func (b *Book) FetchAssetMetaForAsset(ctx context.Context, assetID asset.ID) (*proof.MetaReveal, error)
- func (b *Book) GetOrCreateEvent(ctx context.Context, status Status, transfer IncomingTransfer) (*Event, error)
- func (b *Book) GetPendingEvents(ctx context.Context) ([]*Event, error)
- func (b *Book) HasDelegationKey(ctx context.Context, assetID asset.ID) (bool, error)
- func (b *Book) InsertScriptKey(ctx context.Context, scriptKey asset.ScriptKey, keyType asset.ScriptKeyType) error
- func (b *Book) IsLocalKey(ctx context.Context, key keychain.KeyDescriptor) bool
- func (b *Book) LastEventHeightByVersion(ctx context.Context, version Version) (uint32, error)
- func (b *Book) ListAddrs(ctx context.Context, params QueryParams) ([]AddrWithKeyInfo, error)
- func (b *Book) NewAddress(ctx context.Context, addrVersion Version, specifier asset.Specifier, ...) (*AddrWithKeyInfo, error)
- func (b *Book) NewAddressWithKeys(ctx context.Context, addrVersion Version, specifier asset.Specifier, ...) (*AddrWithKeyInfo, error)
- func (b *Book) NextInternalKey(ctx context.Context, family keychain.KeyFamily) (keychain.KeyDescriptor, error)
- func (b *Book) NextScriptKey(ctx context.Context, family keychain.KeyFamily) (asset.ScriptKey, error)
- func (b *Book) QueryAssetInfo(ctx context.Context, specifier asset.Specifier) (asset.AssetGroup, error)
- func (b *Book) QueryEvent(ctx context.Context, addr *AddrWithKeyInfo, outpoint wire.OutPoint) (*Event, error)
- func (b *Book) QueryEvents(ctx context.Context, query EventQueryParams) ([]*Event, error)
- func (b *Book) RegisterSubscriber(receiver *fn.EventReceiver[*AddrWithKeyInfo], deliverExisting bool, ...) error
- func (b *Book) RemoveSubscriber(subscriber *fn.EventReceiver[*AddrWithKeyInfo]) error
- func (b *Book) SetAddrManaged(ctx context.Context, addr *AddrWithKeyInfo, managedFrom time.Time) error
- func (b *Book) SyncAssetGroup(ctx context.Context, groupKey btcec.PublicKey) error
- type BookConfig
- type ChainParams
- type DelegationKeyChecker
- type ErrorTestCase
- type Event
- type EventQueryParams
- type EventStorage
- type IncomingTransfer
- type KeyRing
- type NewAddrOpt
- type NewAddressParams
- type QueryParams
- type Status
- type Storage
- type Tap
- func (a *Tap) AssetType() asset.Type
- func (a *Tap) AttachGenesis(gen asset.Genesis)
- func (a *Tap) Copy() *Tap
- func (a *Tap) Decode(r io.Reader) error
- func (a *Tap) DecodeRecords() []tlv.Record
- func (a *Tap) Encode(w io.Writer) error
- func (a *Tap) EncodeAddress() (string, error)
- func (a *Tap) EncodeRecords() []tlv.Record
- func (a *Tap) Net() (*ChainParams, error)
- func (a *Tap) ScriptKeyForAssetID(assetID asset.ID) (*btcec.PublicKey, error)
- func (a *Tap) Specifier() asset.Specifier
- func (a *Tap) String() string
- func (a *Tap) SupportsGroupedAssets() bool
- func (a *Tap) TaprootOutputKey() (*btcec.PublicKey, error)
- func (a *Tap) UsesSendManifests() bool
- type TestAddress
- type TestVectors
- type ValidTestCase
- type Version
Constants ¶
const ( // MainnetHRP is the HRP for mainnet. MainnetHRP = "tapbc" // TestnetHRP is the HRP for testnet. TestnetHRP = "taptb" // Testnet4HRP is the HRP for testnet4. Testnet4HRP = "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" )
const Subsystem = "ADDR"
Subsystem defines the logging code for this subsystem.
Variables ¶
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: zero amount cannot be used for normal asset " + "addresses of V0 or V1", ) // 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") // ErrInvalidProofCourierAddr is returned when we attempt to create a // Taproot Asset address with a proof courier address that is not valid. ErrInvalidProofCourierAddr = errors.New( "address: invalid proof courier address", ) )
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") // ErrAssetGroupQueryFailed is returned when querying for an asset group // fails. ErrAssetGroupQueryFailed = fmt.Errorf("asset group query failed") // ErrAssetMetaQueryFailed is returned when querying for asset metadata // fails. ErrAssetMetaQueryFailed = fmt.Errorf("asset meta query failed") // ErrDelegationKeyQueryFailed is returned when querying for delegation // key fails. ErrDelegationKeyQueryFailed = fmt.Errorf("delegation key query failed") )
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, } // TestNet4Tap holds the chain params for testnet4. TestNet4Tap = ChainParams{ Params: &chaincfg.TestNet4Params, TapHRP: Testnet4HRP, } // 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, } )
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 ¶
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
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
RandProofCourierAddr returns a proof courier address with fields populated with valid but random values.
func RandProofCourierAddrForVersion ¶ added in v0.7.0
RandProofCourierAddrForVersion returns a proof courier address with fields populated with valid but dummy values for the given address version.
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 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
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.
func RandAddrWithVersion ¶ added in v0.7.0
func RandAddrWithVersion(t testing.TB, params *ChainParams, proofCourierAddr url.URL, addrVersion Version) (*AddrWithKeyInfo, *asset.Genesis, *asset.GroupKey)
RandAddrWithVersion creates a random address for testing, using the specified version.
func RandAddrWithVersionAndScriptKey ¶ added in v0.7.0
func RandAddrWithVersionAndScriptKey(t testing.TB, params *ChainParams, proofCourierAddr url.URL, addrVersion Version, scriptKey asset.ScriptKey) (*AddrWithKeyInfo, *asset.Genesis, *asset.GroupKey)
RandAddrWithVersionAndScriptKey creates a random address for testing, using the specified version and script key.
type AssetOutput ¶ added in v0.7.0
type AssetOutput struct {
// Amount is the amount of this asset output.
Amount uint64
// ScriptKey is the serialized script key that can be used to spend the
// output.
ScriptKey asset.ScriptKey
}
AssetOutput holds the information about a single asset output that was sent as part of an incoming asset transfer. Each event can have multiple outputs, in case multiple tranches of a grouped asset were transferred using a V2 address.
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.
SyncAssetInfo(ctx context.Context, specifier asset.Specifier) 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) AddrByScriptKeyAndVersion ¶ added in v0.7.0
func (b *Book) AddrByScriptKeyAndVersion(ctx context.Context, scriptKey *btcec.PublicKey, version Version) (*AddrWithKeyInfo, error)
AddrByScriptKeyAndVersion returns a single address based on its script key and version or a sql.ErrNoRows error if no such address exists.
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) DecDisplayForAssetID ¶ added in v0.6.1
DecDisplayForAssetID attempts to fetch the meta reveal for a specific asset ID and extract the decimal display value from 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, transfer IncomingTransfer) (*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 ¶
GetPendingEvents returns all events that are not yet in status complete from the database.
func (*Book) HasDelegationKey ¶ added in v0.7.0
HasDelegationKey checks if we control the delegation key for the given asset ID. Returns true if we have the private key for the asset's delegation key, false otherwise.
NOTE: This is part of the DelegationKeyChecker interface.
func (*Book) InsertScriptKey ¶ added in v0.4.0
func (b *Book) InsertScriptKey(ctx context.Context, scriptKey asset.ScriptKey, keyType asset.ScriptKeyType) error
InsertScriptKey inserts an address related script key into the database.
func (*Book) IsLocalKey ¶
IsLocalKey returns true if the key is under the control of the wallet and can be derived by it.
func (*Book) LastEventHeightByVersion ¶ added in v0.7.0
LastEventHeightByVersion returns the last event height for a given address version.
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, specifier asset.Specifier, 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, specifier asset.Specifier, 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, specifier asset.Specifier) (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 ¶
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 DelegationKeyChecker ¶ added in v0.7.0
type DelegationKeyChecker interface {
// HasDelegationKey checks if we control the delegation key for the
// given asset ID. Returns true if we have the private key for the
// asset's delegation key, false otherwise.
HasDelegationKey(ctx context.Context, assetID asset.ID) (bool, error)
}
DelegationKeyChecker is used to verify that we control the delegation key for a given asset, which is required for creating supply commitments.
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
// The map of asset ID to AssetOutput that contains the amount and
// script key of each asset output that was sent as part of the incoming
// asset transfer.
Outputs map[asset.ID]AssetOutput
// ConfirmationHeight is the block height at which the incoming asset
// transfer transaction was first confirmed.
ConfirmationHeight uint32
// HasAllProofs indicates that a proof for each output of this transfer
// was imported. We don't keep a reference to them in memory as the
// proofs themselves can be large. The proofs can be fetched by the
// script keys of the address.
HasAllProofs 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
// CreationTimeTo is the latest creation time to query for
// (inclusive). Can be set to nil to return events of all creation
// times.
CreationTimeTo *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,
transfer IncomingTransfer) (*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 IncomingTransfer ¶ added in v0.7.0
type IncomingTransfer struct {
// Addr is the Taproot Asset address that was used to receive the
// assets.
Addr *AddrWithKeyInfo
// Tx is the on-chain transaction that contains the Taproot Asset
// commitment for the incoming asset transfer.
Tx *wire.MsgTx
// OutputIdx is the index of the output in the transaction that contains
// the Taproot Asset commitment for the incoming asset transfer.
OutputIdx uint32
// CommitmentVersion is the version of the Taproot Asset commitment
// that was used to create the Taproot Asset address.
CommitmentVersion commitment.TapCommitmentVersion
// TaprootAssetRoot is the root of the Taproot Asset commitment tree
// that was used to create the Taproot Asset address.
TaprootAssetRoot [sha256.Size]byte
// BlockHeight is the height of the block that contains the transaction.
BlockHeight uint32
// BlockHash is the hash of the block that contains the transaction.
BlockHash *chainhash.Hash
// Outputs is a map of asset IDs to the outputs that are being sent.
Outputs map[asset.ID]AssetOutput
}
IncomingTransfer is a struct that holds the information about an incoming asset transfer that was detected on-chain. This is used to create an Event instance that can be stored in the database.
func NewTransferFromFragment ¶ added in v0.7.0
func NewTransferFromFragment(addr *AddrWithKeyInfo, block *wire.MsgBlock, fragment *proof.SendFragment, outputs map[asset.ID]AssetOutput) (IncomingTransfer, error)
NewTransferFromFragment creates a new IncomingTransfer from a SendFragment, the block that contains the TX and the address that was used to receive the assets. This can only be used for V2 addresses.
func NewTransferFromWalletTx ¶ added in v0.7.0
func NewTransferFromWalletTx(addr *AddrWithKeyInfo, walletTx *lndclient.Transaction, outputIdx uint32, outputs map[asset.ID]AssetOutput) (IncomingTransfer, error)
NewTransferFromWalletTx creates a new IncomingTransfer from a wallet transaction and the address that was used to receive the assets. This can only be used for V0 and V1 addresses.
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 NewAddressParams ¶ added in v0.7.0
type NewAddressParams struct {
// Version is the version of the address to create.
Version Version
// ChainParams is the chain parameters that the address will be used on.
ChainParams *ChainParams
// Amount is the number of asset units being requested by the receiver.
// The amount is allowed to be zero for V2 addresses, where the sender
// can choose the amount to send.
Amount uint64
// Genesis is the asset genesis metadata that this address is created
// for. This is used to derive the asset ID of the address and is
// optional for V2 addresses that have a group key set.
Genesis asset.Genesis
// GroupKey is the asset group key that is used to receive assets. For
// V0/V1 addresses, this is purely informational and is not used. For V2
// addresses this must be used for assets that belong to a group, as
// receiving through just a single asset ID is not desired for grouped
// assets.
GroupKey *btcec.PublicKey
// GroupWitness is the witness that proves the group key is valid. This
// must only be set if the GroupKey is set.
GroupWitness wire.TxWitness
// ScriptKey is the Taproot output key that is used to lock the assets
// received to this address.
ScriptKey btcec.PublicKey
// InternalKey is the on-chain Taproot internal key that is used to
// derive the Taproot output key for the address.
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 is optional and can be nil if no tapscript sibling is
// desired. If set, it must be a valid tapscript sibling that is not a
// Taproot Asset commitment.
TapscriptSibling *commitment.TapscriptPreimage
// ProofCourierAddr is the address of the proof courier that will be
// used to distribute related proofs for this address.
ProofCourierAddr url.URL
}
NewAddressParams is a set of parameters that can be used to create a new Taproot Asset 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 specifier.
QueryAssetGroup(context.Context, asset.Specifier) (*asset.AssetGroup,
error)
// QueryAssetGroupByID attempts to locate the asset group information
// (genesis + group key) associated with a given asset.
QueryAssetGroupByID(context.Context, asset.ID) (*asset.AssetGroup,
error)
// QueryAssetGroupByGroupKey fetches the asset group with a matching
// tweaked key, including the genesis information used to create the
// group.
QueryAssetGroupByGroupKey(context.Context,
*btcec.PublicKey) (*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)
// AddrByScriptKeyAndVersion returns a single address based on its
// script key and version or a sql.ErrNoRows error if no such address
// exists.
AddrByScriptKeyAndVersion(context.Context, *btcec.PublicKey,
Version) (*AddrWithKeyInfo, error)
// SetAddrManaged sets an address as being managed by the internal
// wallet.
SetAddrManaged(ctx context.Context, addr *AddrWithKeyInfo,
managedFrom time.Time) error
// LastEventHeightByVersion returns the last event height for a given
// address version.
LastEventHeightByVersion(ctx context.Context,
version Version) (uint32, 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.
InsertScriptKey(ctx context.Context, scriptKey asset.ScriptKey,
keyType asset.ScriptKeyType) error
// FetchAllAssetMeta attempts to fetch all asset meta known to the
// database.
FetchAllAssetMeta(
ctx context.Context) (map[asset.ID]*proof.MetaReveal, error)
// FetchInternalKeyLocator attempts to fetch the key locator information
// for the given raw internal key. If the key cannot be found, then
// ErrInternalKeyNotFound is returned.
FetchInternalKeyLocator(ctx context.Context,
rawKey *btcec.PublicKey) (keychain.KeyLocator, 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. This will be all zeroes for
// V2 addresses that have a group key set.
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 the asset's Taproot output key encumbering the
// different ways an asset can be spent. This is different for V2
// addresses, where this key is not the Taproot output key but the
// Taproot internal key (the bare/raw key) of the asset script key (not
// to be confused with the InternalKey below, which is for the on-chain
// part of the address). The sender will use this key to encrypt the
// send fragment that they post to the proof courier's mailbox. The raw
// script key will also be used by the sender to derive different
// Taproot output script keys for each asset ID.
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.
// The amount is allowed to be zero for V2 addresses, where the sender
// will post a fragment containing the asset IDs and amounts to the
// proof courier's mailbox.
Amount uint64
// ProofCourierAddr is the address of the proof courier that will be
// used to distribute related proofs for this address. For V2 addresses
// the proof courier address is mandatory and must be a valid auth
// mailbox 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(params NewAddressParams, opts ...NewAddrOpt) (*Tap, error)
New creates an address for receiving a Taproot asset.
func (*Tap) AttachGenesis ¶
AttachGenesis attaches the asset's genesis metadata to the address.
func (*Tap) DecodeRecords ¶
DecodeRecords provides all records known for an address for proper decoding.
func (*Tap) EncodeAddress ¶
EncodeAddress returns a bech32m string encoding of a Taproot Asset address.
func (*Tap) EncodeRecords ¶
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) ScriptKeyForAssetID ¶ added in v0.7.0
ScriptKeyForAssetID returns the script key for this address for the given asset ID. For V2 addresses, this will derive a unique script key for the asset ID using the internal script key and a Pedersen commitment. For addresses before V2, the script key is always the Taproot output key as specified in the address directly.
func (*Tap) Specifier ¶ added in v0.7.0
Specifier returns the asset specifier for this address. For backward compatibility with V0/V1 addresses, we create a specifier with a group key only if the asset ID is zero. For V0 and V1 addresses the group key can be set, but it is not actually used, so we always must include the asset ID in the specifier.
func (*Tap) SupportsGroupedAssets ¶ added in v0.7.0
SupportsGroupedAssets returns true if the address supports grouped assets.
func (*Tap) TaprootOutputKey ¶
TaprootOutputKey returns the on-chain Taproot output key.
func (*Tap) UsesSendManifests ¶ added in v0.7.0
UsesSendManifests returns true if the address requires the new authmailbox proof courier type to transport a send manifest from the sender to the receiver. If this is true, it means the address supports sending grouped assets and also requires unique script keys for each asset ID.
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
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.
func RandVersion ¶ added in v0.7.0
func RandVersion() Version
RandVersion returns a random address version for testing.
func UnmarshalVersion ¶ added in v0.5.0
func UnmarshalVersion(version taprpc.AddrVersion) (Version, error)
UnmarshalVersion parses an address version from the RPC variant.