fabtoken

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PublicParameters is the key to be used to look up fabtoken parameters
	PublicParameters = "fabtoken"
	DefaultPrecision = uint64(64)
)

Variables

This section is empty.

Functions

func IssueValidate added in v0.4.0

func IssueValidate(ctx *Context) error

func TransferBalanceValidate

func TransferBalanceValidate(ctx *Context) error

TransferBalanceValidate checks that the sum of the inputs is equal to the sum of the outputs

func TransferHTLCValidate

func TransferHTLCValidate(ctx *Context) error

TransferHTLCValidate checks the validity of the HTLC scripts, if any

func TransferSignatureValidate

func TransferSignatureValidate(ctx *Context) error

TransferSignatureValidate validates the signatures for the inputs spent by an action

Types

type ActionDeserializer added in v0.4.0

type ActionDeserializer struct{}

func (*ActionDeserializer) DeserializeActions added in v0.4.0

func (a *ActionDeserializer) DeserializeActions(tr *driver.TokenRequest) ([]*IssueAction, []*TransferAction, error)

type AuditorService added in v0.4.0

type AuditorService struct{}

func NewAuditorService added in v0.4.0

func NewAuditorService() *AuditorService

func (*AuditorService) AuditorCheck added in v0.4.0

func (s *AuditorService) AuditorCheck(ctx context.Context, request *driver.TokenRequest, metadata *driver.TokenRequestMetadata, anchor string) error

AuditorCheck verifies if the passed tokenRequest matches the tokenRequestMetadata fabtoken does not make use of AuditorCheck as the token request contains token information in the clear

type IssueAction

type IssueAction struct {
	// issuer's public key
	Issuer driver.Identity
	// new tokens to be issued
	Outputs []*Output
	// metadata of the issue action
	Metadata map[string][]byte
}

IssueAction encodes a fabtoken Issue

func (*IssueAction) Deserialize

func (i *IssueAction) Deserialize(raw []byte) error

Deserialize un-marshals IssueAction

func (*IssueAction) GetIssuer

func (i *IssueAction) GetIssuer() []byte

GetIssuer returns the issuer encoded in IssueAction

func (*IssueAction) GetMetadata

func (i *IssueAction) GetMetadata() map[string][]byte

GetMetadata returns the IssueAction metadata

func (*IssueAction) GetOutputs

func (i *IssueAction) GetOutputs() []driver.Output

GetOutputs returns the outputs in an IssueAction

func (*IssueAction) GetSerializedOutputs

func (i *IssueAction) GetSerializedOutputs() ([][]byte, error)

GetSerializedOutputs returns the serialization of the outputs in an IssueAction

func (*IssueAction) IsAnonymous

func (i *IssueAction) IsAnonymous() bool

IsAnonymous returns false, indicating that the identity of issuers in fabtoken is revealed during issue

func (*IssueAction) IsGraphHiding added in v0.4.0

func (i *IssueAction) IsGraphHiding() bool

IsGraphHiding returns false, indicating that fabtoken does not hide the transaction graph

func (*IssueAction) NumOutputs

func (i *IssueAction) NumOutputs() int

NumOutputs returns the number of outputs in an IssueAction

func (*IssueAction) Serialize

func (i *IssueAction) Serialize() ([]byte, error)

Serialize marshals IssueAction

type IssueService added in v0.4.0

type IssueService struct {
	PublicParamsManager driver.PublicParamsManager
	WalletService       driver.WalletService
	Deserializer        driver.Deserializer
}

func NewIssueService added in v0.4.0

func NewIssueService(publicParamsManager driver.PublicParamsManager, walletService driver.WalletService, deserializer driver.Deserializer) *IssueService

func (*IssueService) DeserializeIssueAction added in v0.4.0

func (s *IssueService) DeserializeIssueAction(raw []byte) (driver.IssueAction, error)

DeserializeIssueAction un-marshals the passed bytes into an IssueAction If unmarshalling fails, then DeserializeIssueAction returns an error

func (*IssueService) Issue added in v0.4.0

func (s *IssueService) Issue(ctx context.Context, issuerIdentity driver.Identity, tokenType token2.Type, values []uint64, owners [][]byte, opts *driver.IssueOptions) (driver.IssueAction, *driver.IssueMetadata, error)

Issue returns an IssueAction as a function of the passed arguments Issue also returns a serialization OutputMetadata associated with issued tokens and the identity of the issuer

func (*IssueService) VerifyIssue added in v0.4.0

func (s *IssueService) VerifyIssue(tr driver.IssueAction, tokenInfos [][]byte) error

VerifyIssue checks if the outputs of an IssueAction match the passed tokenInfos

type Output

type Output fabtoken.Token

Output carries the output of an action

func (*Output) Deserialize added in v0.4.0

func (t *Output) Deserialize(bytes []byte) error

Deserialize unmarshals Token

func (*Output) GetOwner added in v0.4.0

func (t *Output) GetOwner() []byte

func (*Output) IsRedeem

func (t *Output) IsRedeem() bool

IsRedeem returns true if the owner of a Token is empty todo update interface to account for nil t.Token.Owner and nil t.Token

func (*Output) Serialize

func (t *Output) Serialize() ([]byte, error)

Serialize marshals a Token

type OutputMetadata

type OutputMetadata fabtoken.Metadata

OutputMetadata contains a serialization of the issuer of the token. type, value and owner of token can be derived from the token itself.

func (*OutputMetadata) Deserialize

func (m *OutputMetadata) Deserialize(b []byte) error

Deserialize un-marshals Metadata

func (*OutputMetadata) Serialize

func (m *OutputMetadata) Serialize() ([]byte, error)

Serialize un-marshals Metadata

type PublicParams

type PublicParams struct {
	// Label is the label associated with the PublicParams.
	// It can be used by the driver for versioning purpose.
	Label string
	// The precision of token quantities
	QuantityPrecision uint64
	// This is set when audit is enabled
	Auditor []byte
	// This encodes the list of authorized issuers
	Issuers [][]byte
	// MaxToken is the maximum quantity a token can hold
	MaxToken uint64
}

PublicParams is the public parameters for fabtoken

func NewPublicParamsFromBytes

func NewPublicParamsFromBytes(raw []byte, label string) (*PublicParams, error)

NewPublicParamsFromBytes deserializes the raw bytes into public parameters The resulting public parameters are labeled with the passed label

func Setup

func Setup() (*PublicParams, error)

Setup initializes PublicParams

func (*PublicParams) AddAuditor

func (pp *PublicParams) AddAuditor(auditor driver.Identity)

AddAuditor sets the Auditor field in PublicParams to the passed identity

func (*PublicParams) AddIssuer

func (pp *PublicParams) AddIssuer(issuer driver.Identity)

AddIssuer adds the passed issuer to the array of Issuers in PublicParams

func (*PublicParams) AuditorIdentity

func (pp *PublicParams) AuditorIdentity() driver.Identity

AuditorIdentity returns the auditor identity encoded in PublicParams

func (*PublicParams) Auditors

func (pp *PublicParams) Auditors() []driver.Identity

Auditors returns the list of authorized auditors fabtoken only supports a single auditor

func (*PublicParams) Bytes

func (pp *PublicParams) Bytes() ([]byte, error)

Bytes marshals PublicParams

func (*PublicParams) CertificationDriver

func (pp *PublicParams) CertificationDriver() string

CertificationDriver returns the label of the PublicParams From the label, one can deduce what certification process will be used if any.

func (*PublicParams) ComputeMaxTokenValue

func (pp *PublicParams) ComputeMaxTokenValue() uint64

func (*PublicParams) Deserialize

func (pp *PublicParams) Deserialize(raw []byte) error

Deserialize un-marshals the passed bytes into PublicParams

func (*PublicParams) GraphHiding

func (pp *PublicParams) GraphHiding() bool

GraphHiding indicates if the PublicParams corresponds to a driver that hides the transaction graph fabtoken does not hide the graph, hence, GraphHiding returns false

func (*PublicParams) Identifier

func (pp *PublicParams) Identifier() string

Identifier returns the label associated with the PublicParams todo shall we used Identifier instead of Label?

func (*PublicParams) MaxTokenValue

func (pp *PublicParams) MaxTokenValue() uint64

MaxTokenValue returns the maximum value that a token can hold according to PublicParams

func (*PublicParams) Precision

func (pp *PublicParams) Precision() uint64

Precision returns the quantity precision encoded in PublicParams

func (*PublicParams) Serialize

func (pp *PublicParams) Serialize() ([]byte, error)

Serialize marshals a wrapper around PublicParams (SerializedPublicParams)

func (*PublicParams) String added in v0.3.0

func (pp *PublicParams) String() string

func (*PublicParams) TokenDataHiding

func (pp *PublicParams) TokenDataHiding() bool

TokenDataHiding indicates if the PublicParams corresponds to a driver that hides token data fabtoken does not hide token data, hence, TokenDataHiding returns false

func (*PublicParams) Validate

func (pp *PublicParams) Validate() error

Validate validates the public parameters

type Service

type Service struct {
	*common.Service[*PublicParams]
}

func NewService

func NewService(
	logger logging.Logger,
	ws *common.WalletService,
	ppm common.PublicParametersManager[*PublicParams],
	identityProvider driver.IdentityProvider,
	serializer driver.Serializer,
	deserializer driver.Deserializer,
	configuration driver.Configuration,
	issueService driver.IssueService,
	transferService driver.TransferService,
	auditorService driver.AuditorService,
	tokensService driver.TokensService,
	authorization driver.Authorization,
) (*Service, error)

func (*Service) Validator

func (s *Service) Validator() (driver.Validator, error)

type TokenLoader

type TokenLoader interface {
	GetTokens(ids []*token.ID) ([]*token.Token, error)
}

type TokenVault

type TokenVault interface {
	PublicParams() ([]byte, error)
	UnspentTokensIteratorBy(ctx context.Context, id string, tokenType token.Type) (driver.UnspentTokensIterator, error)
	ListHistoryIssuedTokens() (*token.IssuedTokens, error)
	Balance(id string, tokenType token.Type) (uint64, error)
}

type TokensService added in v0.4.0

type TokensService struct {
	*common.TokensService
	OutputTokenFormat token2.Format
}

func NewTokensService added in v0.4.0

func NewTokensService(pp *PublicParams) (*TokensService, error)

func (*TokensService) Deobfuscate added in v0.4.0

func (s *TokensService) Deobfuscate(output []byte, outputMetadata []byte) (*token2.Token, driver.Identity, token2.Format, error)

Deobfuscate returns a deserialized token and the identity of its issuer

func (*TokensService) SupportedTokenFormats added in v0.4.0

func (s *TokensService) SupportedTokenFormats() []token2.Format

type TransferAction

type TransferAction struct {
	// identifier of token to be transferred
	Inputs []*token.ID
	// InputTokens are the inputs transferred by this action
	InputTokens []*Output
	// outputs to be created as a result of the transfer
	Outputs []*Output
	// Metadata contains the transfer action's metadata
	Metadata map[string][]byte
}

TransferAction encodes a fabtoken transfer

func (*TransferAction) Deserialize

func (t *TransferAction) Deserialize(raw []byte) error

Deserialize un-marshals TransferAction

func (*TransferAction) GetInputs

func (t *TransferAction) GetInputs() []*token.ID

GetInputs returns inputs of the TransferAction

func (*TransferAction) GetMetadata

func (t *TransferAction) GetMetadata() map[string][]byte

GetMetadata returns the transfer action's metadata

func (*TransferAction) GetOutputs

func (t *TransferAction) GetOutputs() []driver.Output

GetOutputs returns the outputs in a TransferAction

func (*TransferAction) GetSerialNumbers added in v0.4.0

func (t *TransferAction) GetSerialNumbers() []string

func (*TransferAction) GetSerializedInputs added in v0.4.0

func (t *TransferAction) GetSerializedInputs() ([][]byte, error)

func (*TransferAction) GetSerializedOutputs

func (t *TransferAction) GetSerializedOutputs() ([][]byte, error)

GetSerializedOutputs returns the serialization of the outputs in a TransferAction

func (*TransferAction) IsGraphHiding

func (t *TransferAction) IsGraphHiding() bool

IsGraphHiding returns false, indicating that fabtoken does not hide the transaction graph

func (*TransferAction) IsRedeemAt

func (t *TransferAction) IsRedeemAt(index int) bool

IsRedeemAt returns true if the output at the specified index is a redeemed output todo update interface to account for nil t.outputs[index]

func (*TransferAction) NumOutputs

func (t *TransferAction) NumOutputs() int

NumOutputs returns the number of outputs in an TransferAction

func (*TransferAction) Serialize

func (t *TransferAction) Serialize() ([]byte, error)

Serialize marshals TransferAction

func (*TransferAction) SerializeOutputAt

func (t *TransferAction) SerializeOutputAt(index int) ([]byte, error)

SerializeOutputAt marshals the output at the specified index in TransferAction

type TransferService added in v0.4.0

type TransferService struct {
	Logger                  logging.Logger
	PublicParametersManager common.PublicParametersManager[*PublicParams]
	WalletService           driver.WalletService
	TokenLoader             TokenLoader
	Deserializer            driver.Deserializer
}

func NewTransferService added in v0.4.0

func NewTransferService(
	logger logging.Logger,
	publicParametersManager common.PublicParametersManager[*PublicParams],
	walletService driver.WalletService,
	tokenLoader TokenLoader,
	deserializer driver.Deserializer,
) *TransferService

func (*TransferService) DeserializeTransferAction added in v0.4.0

func (s *TransferService) DeserializeTransferAction(raw []byte) (driver.TransferAction, error)

DeserializeTransferAction un-marshals a TransferAction from the passed array of bytes. DeserializeTransferAction returns an error, if the un-marshalling fails.

func (*TransferService) Transfer added in v0.4.0

Transfer returns a TransferAction as a function of the passed arguments It also returns the corresponding TransferMetadata

func (*TransferService) VerifyTransfer added in v0.4.0

func (s *TransferService) VerifyTransfer(tr driver.TransferAction, outputsMetadata [][]byte) error

VerifyTransfer checks the outputs in the TransferAction against the passed tokenInfos

type Validator

func NewValidator

func NewValidator(logger logging.Logger, pp *PublicParams, deserializer driver.Deserializer, extraValidators ...ValidateTransferFunc) *Validator

type WalletFactory added in v0.4.0

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

func NewWalletFactory added in v0.4.0

func NewWalletFactory(logger logging.Logger, identityProvider driver.IdentityProvider, tokenVault TokenVault) *WalletFactory

func (*WalletFactory) NewWallet added in v0.4.0

func (w *WalletFactory) NewWallet(role driver.IdentityRole, walletRegistry common.WalletRegistry, info driver.IdentityInfo, id string) (driver.Wallet, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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