secp256k1fx

package
v1.22.21 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: BSD-3-Clause Imports: 23 Imported by: 23

Documentation

Index

Constants

View Source
const (
	CostPerSignature uint64 = 1000
)
View Source
const Name = "secp256k1fx"

Variables

View Source
var (
	ErrWrongVMType                    = errors.New("wrong vm type")
	ErrWrongTxType                    = errors.New("wrong tx type")
	ErrWrongOpType                    = errors.New("wrong operation type")
	ErrWrongUTXOType                  = errors.New("wrong utxo type")
	ErrWrongInputType                 = errors.New("wrong input type")
	ErrWrongCredentialType            = errors.New("wrong credential type")
	ErrWrongOwnerType                 = errors.New("wrong owner type")
	ErrMismatchedAmounts              = errors.New("utxo amount and input amount are not equal")
	ErrWrongNumberOfUTXOs             = errors.New("wrong number of utxos for the operation")
	ErrWrongMintCreated               = errors.New("wrong mint output created from the operation")
	ErrTimelocked                     = errors.New("output is time locked")
	ErrTooManySigners                 = errors.New("input has more signers than expected")
	ErrTooFewSigners                  = errors.New("input has less signers than expected")
	ErrInputOutputIndexOutOfBounds    = errors.New("input referenced a nonexistent address in the output")
	ErrInputCredentialSignersMismatch = errors.New("input expected a different number of signers than provided in the credential")
	ErrWrongSig                       = errors.New("wrong signature")
)
View Source
var (
	ErrNilInput                    = errors.New("nil input")
	ErrInputIndicesNotSortedUnique = errors.New("address indices not sorted and unique")
)
View Source
var (
	ErrNilOutput            = errors.New("nil output")
	ErrOutputUnspendable    = errors.New("output is unspendable")
	ErrOutputUnoptimized    = errors.New("output representation should be optimized")
	ErrAddrsNotSortedUnique = errors.New("addresses not sorted and unique")
)
View Source
var ErrNilCredential = errors.New("nil credential")
View Source
var ErrNoValueInput = errors.New("input has no value")
View Source
var (
	ErrNoValueOutput = errors.New("output has no value")
)
View Source
var (

	// ID that this Fx uses when labeled
	ID = ids.ID{'s', 'e', 'c', 'p', '2', '5', '6', 'k', '1', 'f', 'x'}
)

Functions

func WrapKeychain added in v1.11.14

func WrapKeychain(kc *Keychain) keychain.Keychain

WrapKeychain wraps a Keychain to implement the ledger keychain interface

Types

type Credential

type Credential struct {
	Sigs [][secp256k1.SignatureLen]byte `serialize:"true" json:"signatures"`
}

func (*Credential) MarshalJSON added in v0.1.1

func (cr *Credential) MarshalJSON() ([]byte, error)

MarshalJSON marshals [cr] to JSON The string representation of each signature is created using the hex formatter

func (*Credential) Verify

func (cr *Credential) Verify() error

type Factory

type Factory struct{}

func (*Factory) New

func (*Factory) New() any

type Fx

type Fx struct {
	VM VM
	// contains filtered or unexported fields
}

Fx describes the secp256k1 feature extension

func (*Fx) Bootstrapped added in v0.1.1

func (fx *Fx) Bootstrapped() error

func (*Fx) Bootstrapping added in v0.1.1

func (*Fx) Bootstrapping() error

func (*Fx) CreateOutput added in v0.1.1

func (*Fx) CreateOutput(amount uint64, ownerIntf interface{}) (interface{}, error)

CreateOutput creates a new output with the provided control group worth the specified amount

func (*Fx) Initialize

func (fx *Fx) Initialize(vmIntf interface{}) error

func (*Fx) InitializeVM

func (fx *Fx) InitializeVM(vmIntf interface{}) error

func (*Fx) VerifyCredentials

func (fx *Fx) VerifyCredentials(utx UnsignedTx, in *Input, cred *Credential, out *OutputOwners) error

VerifyCredentials ensures that the output can be spent by the input with the credential. A nil return values means the output can be spent.

func (*Fx) VerifyOperation

func (fx *Fx) VerifyOperation(txIntf, opIntf, credIntf interface{}, utxosIntf []interface{}) error

func (*Fx) VerifyPermission added in v0.1.1

func (fx *Fx) VerifyPermission(txIntf, inIntf, credIntf, ownerIntf interface{}) error

VerifyPermission returns nil iff [credIntf] proves that [controlGroup] assents to [txIntf]

func (*Fx) VerifySpend

func (fx *Fx) VerifySpend(utx UnsignedTx, in *TransferInput, cred *Credential, utxo *TransferOutput) error

VerifySpend ensures that the utxo can be sent to any address

func (*Fx) VerifyTransfer

func (fx *Fx) VerifyTransfer(txIntf, inIntf, credIntf, utxoIntf interface{}) error

type Input

type Input struct {
	// This input consumes an output, which has an owner list.
	// This input will be spent with a list of signatures.
	// SignatureList[i] is the signature of OwnerList[i]
	SigIndices []uint32 `serialize:"true" json:"signatureIndices"`
}

func (*Input) Cost added in v0.1.1

func (in *Input) Cost() (uint64, error)

func (*Input) Verify

func (in *Input) Verify() error

Verify this input is syntactically valid

type Keychain

type Keychain struct {

	// These can be used to iterate over. However, they should not be modified
	// externally.
	Addrs    set.Set[ids.ShortID]
	EthAddrs set.Set[gethcommon.Address]
	Keys     []*secp256k1.PrivateKey
	// contains filtered or unexported fields
}

Keychain is a collection of keys that can be used to spend outputs

func NewKeychain

func NewKeychain(keys ...*secp256k1.PrivateKey) *Keychain

NewKeychain returns a new keychain containing [keys]

func (*Keychain) Add

func (kc *Keychain) Add(key *secp256k1.PrivateKey)

Add a new key to the key chain

func (Keychain) AddressList added in v1.16.56

func (kc Keychain) AddressList() []ids.ShortID

AddressList returns a list of addresses this keychain manages

func (Keychain) AddressSet added in v1.11.14

func (kc Keychain) AddressSet() set.Set[ids.ShortID]

AddressSet returns a set of addresses this keychain manages

func (Keychain) Addresses

func (kc Keychain) Addresses() set.Set[ids.ShortID]

Addresses returns a set of addresses this keychain manages (implements keychain.Keychain)

func (*Keychain) AsWalletKeychain added in v1.16.56

func (kc *Keychain) AsWalletKeychain() WalletKeychain

AsWalletKeychain wraps a Keychain to implement wallet interfaces

func (Keychain) EthAddresses added in v0.1.1

func (kc Keychain) EthAddresses() set.Set[gethcommon.Address]

EthAddresses returns a list of addresses this keychain manages

func (Keychain) Get

func (kc Keychain) Get(id ids.ShortID) (ukeychain.Signer, bool)

Get a key from the keychain and return whether the key existed. Returns ukeychain.Signer to implement utils/crypto/keychain.Keychain

func (Keychain) GetEth added in v0.1.1

func (kc Keychain) GetEth(addr gethcommon.Address) (ukeychain.Signer, bool)

GetEth gets a key from the keychain by Ethereum address and returns whether the key existed.

func (Keychain) GetEthWallet added in v1.16.56

func (kc Keychain) GetEthWallet(addr gethcommon.Address) (wkeychain.Signer, bool)

GetEthWallet gets a key from the keychain by Ethereum address for wallet operations. Returns wkeychain.Signer to maintain compatibility with wallet code

func (Keychain) GetWallet added in v1.16.56

func (kc Keychain) GetWallet(id ids.ShortID) (wkeychain.Signer, bool)

GetWallet gets a key from the keychain for wallet operations. Returns wkeychain.Signer to maintain compatibility with existing wallet code

func (Keychain) List added in v1.11.14

func (kc Keychain) List() []ids.ShortID

List returns all addresses in the keychain (implements keychain.Keychain)

func (*Keychain) Match

func (kc *Keychain) Match(owners *OutputOwners, time uint64) ([]uint32, []*secp256k1.PrivateKey, bool)

Match attempts to match a list of addresses up to the provided threshold

func (*Keychain) New

func (kc *Keychain) New() (*secp256k1.PrivateKey, error)

New returns a newly generated private key

func (*Keychain) PrefixedString

func (kc *Keychain) PrefixedString(prefix string) string

PrefixedString returns the key chain as a string representation with [prefix] added before every line.

func (*Keychain) Spend

Spend attempts to create an input

func (*Keychain) String

func (kc *Keychain) String() string

type MintOperation

type MintOperation struct {
	MintInput      Input          `serialize:"true" json:"mintInput"`
	MintOutput     MintOutput     `serialize:"true" json:"mintOutput"`
	TransferOutput TransferOutput `serialize:"true" json:"transferOutput"`
}

func (*MintOperation) Cost added in v0.1.1

func (op *MintOperation) Cost() (uint64, error)

func (*MintOperation) InitCtx added in v0.1.1

func (op *MintOperation) InitCtx(ctx *consensusctx.Context)

func (*MintOperation) InitializeContext added in v1.16.56

func (op *MintOperation) InitializeContext(ctx *consensusctx.Context) error

func (*MintOperation) Outs

func (op *MintOperation) Outs() []verify.State

func (*MintOperation) Verify

func (op *MintOperation) Verify() error

type MintOutput

type MintOutput struct {
	verify.IsState `json:"-"`

	OutputOwners `serialize:"true"`
}

func (*MintOutput) InitializeWithContext added in v1.11.14

func (out *MintOutput) InitializeWithContext(ctx context.Context) error

func (*MintOutput) Verify

func (out *MintOutput) Verify() error

type OutputOwners

type OutputOwners struct {
	verify.IsNotState `json:"-"`

	Locktime  uint64        `serialize:"true" json:"locktime"`
	Threshold uint32        `serialize:"true" json:"threshold"`
	Addrs     []ids.ShortID `serialize:"true" json:"addresses"`
	// contains filtered or unexported fields
}

func (*OutputOwners) Addresses

func (out *OutputOwners) Addresses() [][]byte

Addresses returns the addresses that manage this output

func (*OutputOwners) AddressesSet added in v0.1.1

func (out *OutputOwners) AddressesSet() set.Set[ids.ShortID]

AddressesSet returns addresses as a set

func (*OutputOwners) Equals

func (out *OutputOwners) Equals(other *OutputOwners) bool

Equals returns true if the provided owners create the same condition

func (*OutputOwners) Fields added in v0.1.1

func (out *OutputOwners) Fields() (map[string]interface{}, error)

Fields returns JSON keys in a map that can be used with marshal JSON to serialize OutputOwners struct

func (*OutputOwners) InitCtx added in v0.1.1

func (out *OutputOwners) InitCtx(ctx *consensusctx.Context)

InitCtx allows addresses to be formatted into their human readable format during json marshalling.

func (*OutputOwners) MarshalJSON added in v0.1.1

func (out *OutputOwners) MarshalJSON() ([]byte, error)

MarshalJSON marshals OutputOwners as JSON with human readable addresses. OutputOwners.InitCtx must be called before marshalling this or one of the parent objects to json. Uses the OutputOwners.ctx method to format the addresses. Returns errMarshal error if OutputOwners.ctx is not set.

func (*OutputOwners) Sort

func (out *OutputOwners) Sort()

func (*OutputOwners) Verify

func (out *OutputOwners) Verify() error

type PublicKey added in v1.1.11

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

PublicKey wraps the recovered public key bytes

func (*PublicKey) Bytes added in v1.1.11

func (pk *PublicKey) Bytes() []byte

Bytes returns the public key bytes

type RecoverCache added in v1.1.11

type RecoverCache struct {
}

RecoverCache provides a cache for public key recovery operations

func NewRecoverCache added in v1.1.11

func NewRecoverCache(size int) *RecoverCache

NewRecoverCache creates a new recovery cache

func (*RecoverCache) RecoverPublicKeyFromHash added in v1.1.11

func (rc *RecoverCache) RecoverPublicKeyFromHash(hash, sig []byte) (*PublicKey, error)

RecoverPublicKeyFromHash recovers the public key from a hash and signature

type RecoverCacheType added in v1.1.11

type RecoverCacheType = RecoverCache

RecoverCacheType is an alias for compatibility

type TestTx

type TestTx struct{ UnsignedBytes []byte }

TestTx is a minimal implementation of a Tx

func (*TestTx) Bytes

func (tx *TestTx) Bytes() []byte

Bytes returns UnsignedBytes

type TestVM

type TestVM struct {
	Clk   mockable.Clock
	Codec codec.Registry
	Log   log.Logger
}

TestVM is a minimal implementation of a VM

func (*TestVM) Clock

func (vm *TestVM) Clock() *mockable.Clock

func (*TestVM) CodecRegistry added in v0.1.1

func (vm *TestVM) CodecRegistry() codec.Registry

func (*TestVM) Logger

func (vm *TestVM) Logger() log.Logger

type TransferInput

type TransferInput struct {
	Amt   uint64 `serialize:"true" json:"amount"`
	Input `serialize:"true"`
}

func (*TransferInput) Amount

func (in *TransferInput) Amount() uint64

Amount returns the quantity of the asset this input produces

func (*TransferInput) InitCtx added in v0.1.1

func (*TransferInput) InitCtx(*consensusctx.Context)

func (*TransferInput) Verify

func (in *TransferInput) Verify() error

Verify this input is syntactically valid

type TransferOutput

type TransferOutput struct {
	verify.IsState `json:"-"`

	Amt uint64 `serialize:"true" json:"amount"`

	OutputOwners `serialize:"true"`
}

func (*TransferOutput) Amount

func (out *TransferOutput) Amount() uint64

Amount returns the quantity of the asset this output consumes

func (*TransferOutput) InitCtx added in v0.1.1

func (out *TransferOutput) InitCtx(ctx *consensusctx.Context)

InitCtx sets the context for address formatting

func (*TransferOutput) InitializeWithContext added in v1.11.14

func (out *TransferOutput) InitializeWithContext(ctx context.Context) error

func (*TransferOutput) MarshalJSON added in v0.1.1

func (out *TransferOutput) MarshalJSON() ([]byte, error)

MarshalJSON marshals Amt and the embedded OutputOwners struct into a JSON readable format If OutputOwners cannot be serialized then this will return error

func (*TransferOutput) Owners added in v0.1.1

func (out *TransferOutput) Owners() interface{}

func (*TransferOutput) Verify

func (out *TransferOutput) Verify() error

type UnsignedTx added in v0.1.1

type UnsignedTx interface {
	Bytes() []byte
}

UnsignedTx that this Fx is supporting

type VM

type VM interface {
	CodecRegistry() codec.Registry
	Clock() *mockable.Clock
	Logger() log.Logger
}

VM that this Fx must be run by

type WalletKeychain added in v1.16.56

type WalletKeychain struct {
	*Keychain
}

WalletKeychain wraps a Keychain to implement wallet keychain interfaces

func (WalletKeychain) Get added in v1.16.56

func (wkc WalletKeychain) Get(id ids.ShortID) (wkeychain.Signer, bool)

Get implements wallet/keychain.Keychain

func (WalletKeychain) GetEth added in v1.16.56

func (wkc WalletKeychain) GetEth(addr gethcommon.Address) (wkeychain.Signer, bool)

GetEth implements wallet/chain/c.EthKeychain

Jump to

Keyboard shortcuts

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