driver

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: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IssuerRole is the role of an issuer
	IssuerRole = iota
	// AuditorRole is the role of an auditor
	AuditorRole
	// OwnerRole is the role of an owner
	OwnerRole
	// CertifierRole is the role of a certifier
	CertifierRole
)

Variables

View Source
var (
	IdentityRoleStrings = map[IdentityRole]string{
		IssuerRole:    "issuer",
		AuditorRole:   "auditor",
		OwnerRole:     "owner",
		CertifierRole: "certifier",
	}
)

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

func MarshalMeta

func MarshalMeta(v map[string][]byte) ([]byte, error)

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

func UnmarshalMeta

func UnmarshalMeta(raw []byte) (map[string][]byte, error)

Types

type AuditInfoProvider added in v0.4.0

type AuditInfoProvider interface {
	// GetAuditInfo returns the audit information for the given identity, if available.
	GetAuditInfo(identity Identity) ([]byte, error)
}

AuditInfoProvider models a provider of audit information

type AuditorService

type AuditorService interface {
	// AuditorCheck verifies the well-formedness of the passed request with the respect to the passed metadata and anchor
	AuditorCheck(ctx context.Context, request *TokenRequest, metadata *TokenRequestMetadata, anchor string) error
}

AuditorService models the auditor service

type AuditorWallet

type AuditorWallet interface {
	Wallet

	// GetAuditorIdentity returns an auditor identity.
	// Depending on the underlying wallet implementation, this can be a long-term or ephemeral identity.
	GetAuditorIdentity() (Identity, error)
}

AuditorWallet models the wallet of an auditor

type Authorization added in v0.4.0

type Authorization interface {
	// IsMine returns true if the passed token is owned by an owner wallet.
	// It returns the ID of the owner wallet (walletID) and any additional owner identifier (additionalOwners), if supported.
	// It is possible that walletID is empty additionalOwners is not.
	// If walletID is not empty, this means that the corresponding wallet can spend the token directly.
	// If walletID is empty, then additionalOwners must cooperate in some way in order to spend the token.
	IsMine(tok *token.Token) (walletID string, additionalOwners []string, mine bool)
	// AmIAnAuditor return true if the passed TMS contains an auditor wallet for any of the auditor identities
	// defined in the public parameters of the passed TMS.
	AmIAnAuditor() bool
	// Issued returns true if the passed issuer issued the passed token
	Issued(issuer Identity, tok *token.Token) bool
	// OwnerType returns the type of owner (e.g. 'idemix' or 'htlc') and the identity bytes
	OwnerType(raw []byte) (string, []byte, error)
}

Authorization defines method to check the relation between a token and wallets (owner, auditor, etc.)

type CertificationClient

type CertificationClient interface {
	// IsCertified returns true if the passed token-id has been already certified
	IsCertified(id *token.ID) bool
	// RequestCertification requests the certifications of the passed tokens
	RequestCertification(ids ...*token.ID) error
}

type CertificationService

type CertificationService interface {
	// NewCertificationRequest creates a new certification request, in a serialized form, for the passed token ids.
	NewCertificationRequest(ids []*token.ID) ([]byte, error)
	// Certify uses the passed wallet to certify the passed token ids.
	// Certify takes in input the certification request and the token representations as available on the ledger.
	Certify(wallet CertifierWallet, ids []*token.ID, tokens [][]byte, request []byte) ([][]byte, error)
	// VerifyCertifications verifies the validity of the certifications of each token indexed by its token-id.
	// The function returns the result of any processing of these certifications.
	// In the simplest case, VerifyCertifications returns the certifications got in input
	VerifyCertifications(ids []*token.ID, certifications [][]byte) ([][]byte, error)
}

type CertificationStorage

type CertificationStorage interface {
	Exists(id *token.ID) bool
	Store(certifications map[*token.ID][]byte) error
}

type CertifierWallet

type CertifierWallet interface {
	Wallet

	// GetCertifierIdentity returns a certifier identity.
	// Depending on the underlying wallet implementation, this can be a long-term or ephemeral identity.
	GetCertifierIdentity() (Identity, error)
}

CertifierWallet models the wallet of a certifier

type Config added in v0.4.0

type Config interface {
	ID() TMSID
	TranslatePath(path string) string
	UnmarshalKey(key string, rawVal interface{}) error
}

type Configuration added in v0.4.0

type Configuration interface {
	// ID identities the TMS this configuration refers to.
	ID() TMSID
	// IsSet checks to see if the key has been set in any of the data locations
	IsSet(key string) bool
	// UnmarshalKey takes a single key and unmarshals it into a struct.
	// The key must be relative to the TMS this configuration refers to.
	UnmarshalKey(key string, rawVal interface{}) error
	// GetString returns the value associated with the key as a string
	GetString(key string) string
	// GetBool returns the value associated with the key as a bool
	GetBool(key string) bool
	// TranslatePath translates the passed path relative to the config path
	TranslatePath(path string) string
}

Configuration provides functions to access the configuration of a given TMS

type Deserializer

type Deserializer interface {
	// GetOwnerVerifier returns the verifier associated to the passed owner identity
	GetOwnerVerifier(id Identity) (Verifier, error)
	// GetIssuerVerifier returns the verifier associated to the passed issuer identity
	GetIssuerVerifier(id Identity) (Verifier, error)
	// GetAuditorVerifier returns the verifier associated to the passed auditor identity
	GetAuditorVerifier(id Identity) (Verifier, error)
	// GetOwnerMatcher returns an identity matcher for the passed identity audit data
	GetOwnerMatcher(auditData []byte) (Matcher, error)
	// Recipients returns the recipient identities from the given serialized representation
	Recipients(raw Identity) ([]Identity, error)
	// MatchOwnerIdentity returns nil if the given identity matches the given audit information.
	// An error otherwise
	MatchOwnerIdentity(identity Identity, info []byte) error
	// GetOwnerAuditInfo returns the audit information for each identity contained in the given serialized representation
	GetOwnerAuditInfo(id Identity, p AuditInfoProvider) ([][]byte, error)
}

Deserializer models the deserializer of owner, issuer, and auditor identities to get signature verifiers

type Driver

type Driver interface {
	PPReader
	// NewTokenService returns a new TokenManagerService instance.
	NewTokenService(tmsID TMSID, publicParams []byte) (TokenManagerService, error)
	// NewDefaultValidator returns a new Validator instance from the passed public parameters
	NewDefaultValidator(pp PublicParameters) (Validator, error)
}

Driver is the interface that must be implemented by a token driver.

type FullIdentity added in v0.4.0

type FullIdentity interface {
	SigningIdentity
	Verifier
}

type GetStateFnc

type GetStateFnc = func(id token.ID) ([]byte, error)

GetStateFnc models a function that returns the value for the given key from the ledger

type Identity added in v0.4.0

type Identity = view.Identity

Identity represents a generic identity

type IdentityConfiguration added in v0.4.0

type IdentityConfiguration struct {
	ID     string
	URL    string
	Config []byte
	Raw    []byte
}

type IdentityInfo

type IdentityInfo interface {
	// ID returns the identifier of the Identity
	ID() string
	// EnrollmentID returns the enrollment ID of the Identity
	EnrollmentID() string
	// Remote is true if this identity info refers to an identify whose corresponding secret key is not known, it is external/remote
	Remote() bool
	// Get returns the identity and it is audit info.
	// Get might return a different identity at each call depending on the implementation.
	Get() (Identity, []byte, error)
}

IdentityInfo models a long-term identity inside the Identity Provider. An identity has an identifier (ID) and an Enrollment ID, unique identifier. An identity can be remote, meaning that the corresponding secret key is remotely available.

type IdentityProvider

type IdentityProvider interface {
	// RegisterRecipientData stores the passed recipient data
	RegisterRecipientData(data *RecipientData) error

	// GetAuditInfo returns the audit information associated to the passed identity, nil otherwise
	GetAuditInfo(identity Identity) ([]byte, error)

	// GetSigner returns a Signer for passed identity.
	GetSigner(identity Identity) (Signer, error)

	// RegisterVerifier registers a Verifier for passed identity.
	RegisterVerifier(identity Identity, v Verifier) error

	// RegisterSigner registers a Signer and a Verifier for passed identity.
	RegisterSigner(identity Identity, signer Signer, verifier Verifier, signerInfo []byte) error

	// IsMe returns true if a signer was ever registered for the passed identity
	IsMe(party Identity) bool

	// GetEnrollmentID extracts the enrollment ID from the passed audit info
	GetEnrollmentID(identity Identity, auditInfo []byte) (string, error)

	// GetRevocationHandler extracts the revocation handler from the passed audit info
	GetRevocationHandler(identity Identity, auditInfo []byte) (string, error)

	// GetEIDAndRH returns both enrollment ID and revocation handle
	GetEIDAndRH(identity Identity, auditInfo []byte) (string, string, error)

	// Bind binds longTerm to the passed ephemeral identity. The same signer, verifier, and audit of the long term
	// identity is associated to id, if copyAll is true.
	Bind(longTerm Identity, ephemeral Identity, copyAll bool) error

	// RegisterRecipientIdentity register the passed identity as a third-party recipient identity.
	RegisterRecipientIdentity(id Identity) error
}

IdentityProvider manages identity-related concepts like signature signers, verifiers, audit information, and so on.

type IdentityRole

type IdentityRole int

IdentityRole is the role of an identity

type IssueAction

type IssueAction interface {
	// Serialize returns the serialized version of the action
	Serialize() ([]byte, error)
	// NumOutputs returns the number of outputs of the action
	NumOutputs() int
	// GetSerializedOutputs returns the serialized outputs of the action
	GetSerializedOutputs() ([][]byte, error)
	// GetOutputs returns the outputs of the action
	GetOutputs() []Output
	// IsAnonymous returns true if the issuer is anonymous
	IsAnonymous() bool
	// GetIssuer returns the issuer of the action
	GetIssuer() []byte
	// GetMetadata returns the metadata of the action
	GetMetadata() map[string][]byte
	// IsGraphHiding returns true if the action is graph hiding
	IsGraphHiding() bool
}

IssueAction is the action used to issue tokens

type IssueMetadata

type IssueMetadata struct {
	// Issuer is the identity of the issuer
	Issuer Identity

	// Outputs is the list of outputs issued
	Outputs [][]byte
	// OutputsMetadata, for each output we have a OutputsMetadata entry that contains secrets to de-obfuscate the output
	OutputsMetadata [][]byte
	// Receivers, for each output we have a receiver
	Receivers []Identity
	// ReceiversAuditInfos, for each receiver we have audit info to recover the enrollment ID of the receiver
	ReceiversAuditInfos [][]byte

	// ExtraSigners is the list of extra identities that are not part of the issue action per se
	// but needs to sign the request
	ExtraSigners []Identity
}

IssueMetadata contains the metadata of an issue action. In more details, there is an issuer and a list of outputs. For each output, there is a token info and a list of receivers with their audit info to recover their enrollment ID.

type IssueOptions

type IssueOptions struct {
	// Attributes is a container of generic options that might be driver specific
	Attributes map[interface{}]interface{}
}

IssueOptions models the options that can be passed to the issue command

type IssueService

type IssueService interface {
	// Issue generates an IssuerAction whose tokens are issued by the passed identity.
	// The tokens to be issued are passed as pairs (value, owner).
	// In addition, a set of options can be specified to further customize the issue command.
	// The function returns an IssuerAction, the associated metadata, and the identity of the issuer (depending on the implementation, it can be different from
	// the one passed in input).
	// The metadata is an array with an entry for each output created by the action.
	Issue(ctx context.Context, issuerIdentity Identity, tokenType token.Type, values []uint64, owners [][]byte, opts *IssueOptions) (IssueAction, *IssueMetadata, error)

	// VerifyIssue checks the well-formedness of the passed IssuerAction with the respect to the passed metadata
	VerifyIssue(tr IssueAction, metadata [][]byte) error

	// DeserializeIssueAction deserializes the passed bytes into an IssuerAction
	DeserializeIssueAction(raw []byte) (IssueAction, error)
}

IssueService models the token issue service

type IssuerWallet

type IssuerWallet interface {
	Wallet

	// GetIssuerIdentity returns an issuer identity for the passed token type.
	// Depending on the underlying wallet implementation, this can be a long-term or ephemeral identity.
	GetIssuerIdentity(tokenType token.Type) (Identity, error)

	// HistoryTokens returns the list of tokens issued by this wallet filtered using the passed options.
	HistoryTokens(opts *ListTokensOptions) (*token.IssuedTokens, error)
}

IssuerWallet models the wallet of an issuer

type Ledger

type Ledger interface {
	// GetState returns the value for the given key
	GetState(id token.ID) ([]byte, error)
}

Ledger models a read-only ledger

type ListTokensOptions

type ListTokensOptions struct {
	// TokenType is the type of token to list
	TokenType token.Type
	// Context is used to track the operation
	Context context.Context
}

ListTokensOptions contains options that can be used to list tokens from a wallet

type Matcher

type Matcher interface {
	// Match returns true if the passed identity matches this matcher
	Match([]byte) error
}

Matcher models a matcher that can be used to match identities

type NamedFactory added in v0.4.0

type NamedFactory[T any] struct {
	Name   TokenDriverName
	Driver T
}

type NetworkPublicParamsFetcher added in v0.4.0

type NetworkPublicParamsFetcher interface {
	// Fetch fetches the public parameters for the given network, channel, and namespace
	Fetch(network driver.Network, channel driver.Channel, namespace driver.Namespace) ([]byte, error)
}

NetworkPublicParamsFetcher models a public parameters fetcher per network.

type Output

type Output interface {
	// Serialize returns the serialized version of the output
	Serialize() ([]byte, error)
	// IsRedeem returns true if the output is a redeem output
	IsRedeem() bool
	// GetOwner returns the owner of this token
	GetOwner() []byte
}

Output models an output of an action

type OwnerWallet

type OwnerWallet interface {
	Wallet

	// GetRecipientIdentity returns a recipient identity.
	// Depending on the underlying wallet implementation, this can be a long-term or ephemeral identity.
	// Using the returned identity as an index, one can retrieve the following information:
	// - Identity audit info via GetAuditInfo;
	// - TokenMetadata via GetTokenMetadata;
	// - TokenIdentityMetadata via GetTokenMetadataAuditInfo.
	GetRecipientIdentity() (Identity, error)

	// GetAuditInfo returns auditing information for the passed identity
	GetAuditInfo(id Identity) ([]byte, error)

	// GetTokenMetadata returns the public information related to the token to be assigned to passed recipient identity.
	GetTokenMetadata(id Identity) ([]byte, error)

	// GetTokenMetadataAuditInfo returns private information about the token metadata assigned to the passed recipient identity.
	GetTokenMetadataAuditInfo(id Identity) ([]byte, error)

	// ListTokens returns the list of unspent tokens owned by this wallet filtered using the passed options.
	ListTokens(opts *ListTokensOptions) (*token.UnspentTokens, error)

	// ListTokensIterator returns an iterator of unspent tokens owned by this wallet filtered using the passed options.
	ListTokensIterator(opts *ListTokensOptions) (UnspentTokensIterator, error)

	// Balance returns the sun of the amounts, with 64 bits of precision, of the tokens with type and EID equal to those passed as arguments.
	Balance(opts *ListTokensOptions) (uint64, error)

	// EnrollmentID returns the enrollment ID of the owner wallet
	EnrollmentID() string

	// RegisterRecipient register the given recipient data
	RegisterRecipient(data *RecipientData) error

	// Remote returns true if this wallet is verify only, meaning that the corresponding secret key is external to this wallet
	Remote() bool
}

OwnerWallet models the wallet of a token recipient.

type PPHash added in v0.4.0

type PPHash []byte

PPHash is used to model the hash of the raw public parameters. This should avoid confusion between the bytes of the public params themselves and its hash.

type PPMFactory added in v0.4.0

type PPMFactory interface {
	PPReader
	// NewPublicParametersManager returns a new PublicParametersManager instance from the passed public parameters
	NewPublicParametersManager(pp PublicParameters) (PublicParamsManager, error)
	// DefaultValidator returns a new Validator instance from the passed public parameters
	DefaultValidator(pp PublicParameters) (Validator, error)
}

PPMFactory contains the static logic of the driver

type PPManagerFactoryService added in v0.4.0

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

func NewPPManagerFactoryService added in v0.4.0

func NewPPManagerFactoryService(instantiators ...NamedFactory[PPMFactory]) *PPManagerFactoryService

func (*PPManagerFactoryService) DefaultValidator added in v0.4.0

func (s *PPManagerFactoryService) DefaultValidator(pp PublicParameters) (Validator, error)

func (*PPManagerFactoryService) NewPublicParametersManager added in v0.4.0

func (s *PPManagerFactoryService) NewPublicParametersManager(pp PublicParameters) (PublicParamsManager, error)

NewPublicParametersManager returns a new instance of driver.PublicParamsManager for the passed parameters. If no driver is registered for the public params' identifier, it returns an error

func (PPManagerFactoryService) PublicParametersFromBytes added in v0.4.0

func (s PPManagerFactoryService) PublicParametersFromBytes(params []byte) (PublicParameters, error)

PublicParametersFromBytes unmarshals the bytes to a driver.PublicParameters instance. The passed bytes are expected to encode a driver.SerializedPublicParameters instance. If no driver is registered for the public params' identifier, it returns an error.

type PPReader added in v0.4.0

type PPReader interface {
	// PublicParametersFromBytes unmarshals the bytes to a PublicParameters instance.
	PublicParametersFromBytes(params []byte) (PublicParameters, error)
}

type PublicParameters

type PublicParameters interface {
	// Identifier returns the unique identifier of this public parameters.
	Identifier() string
	// TokenDataHiding returns true if the token data is hidden
	TokenDataHiding() bool
	// GraphHiding returns true if the token graph is hidden
	GraphHiding() bool
	// MaxTokenValue returns the maximum token value
	MaxTokenValue() uint64
	// CertificationDriver returns the certification driver identifier
	CertificationDriver() string
	// Bytes returns the marshalled version of the public parameters.
	Bytes() ([]byte, error)
	// Auditors returns the list of auditors.
	Auditors() []Identity
	// Precision returns the precision used to represent the token value.
	Precision() uint64
	// String returns a readable version of the public parameters
	String() string
	// Serialize returns the serialized version of this public parameters
	Serialize() ([]byte, error)
	// Validate returns true if the public parameters are well-formed
	Validate() error
}

PublicParameters is the interface that must be implemented by the driver public parameters.

type PublicParamsFetcher

type PublicParamsFetcher interface {
	// Fetch fetches the public parameters from a repository.
	Fetch() ([]byte, error)
}

PublicParamsFetcher models a public parameters fetcher.

type PublicParamsManager

type PublicParamsManager interface {
	// PublicParameters returns the public parameters.
	PublicParameters() PublicParameters
	// NewCertifierKeyPair generates a new key pair for the certifier, if supported
	NewCertifierKeyPair() ([]byte, []byte, error)
	// PublicParamsHash returns the hash of the raw public parameters
	PublicParamsHash() PPHash
}

PublicParamsManager is the interface that must be implemented by the driver public parameters manager.

type QueryCallback2Func

type QueryCallback2Func func(*token.ID, string, []byte, []byte) error

type QueryCallbackFunc

type QueryCallbackFunc func(*token.ID, []byte) error

type QueryEngine

type QueryEngine interface {
	// IsPending returns true if the transaction the passed id refers to is still pending, false otherwise
	IsPending(id *token.ID) (bool, error)
	// GetStatus returns the status of the passed transaction
	GetStatus(txID string) (TxStatus, string, error)
	// IsMine returns true if the passed id is owned by any known wallet
	IsMine(id *token.ID) (bool, error)
	// UnspentTokensIterator returns an iterator over all unspent tokens
	UnspentTokensIterator() (UnspentTokensIterator, error)
	// UnspentTokensIteratorBy returns an iterator of unspent tokens owned by the passed id and whose type is the passed on.
	// The token type can be empty. In that case, tokens of any type are returned.
	UnspentTokensIteratorBy(ctx context.Context, walletID string, tokenType token.Type) (UnspentTokensIterator, error)
	// ListUnspentTokens returns the list of unspent tokens
	ListUnspentTokens() (*token.UnspentTokens, error)
	// ListAuditTokens returns the audited tokens associated to the passed ids
	ListAuditTokens(ids ...*token.ID) ([]*token.Token, error)
	// ListHistoryIssuedTokens returns the list of issues tokens
	ListHistoryIssuedTokens() (*token.IssuedTokens, error)
	// PublicParams returns the public parameters
	PublicParams() ([]byte, error)
	// GetTokenMetadata retrieves the token information for the passed ids.
	// For each id, the callback is invoked to unmarshal the token information
	GetTokenMetadata(ids []*token.ID) ([][]byte, error)
	// GetTokenOutputs retrieves the token output as stored on the ledger for the passed ids.
	// For each id, the callback is invoked to unmarshal the output
	GetTokenOutputs(ids []*token.ID, callback QueryCallbackFunc) error
	// GetTokenOutputsAndMeta retrieves both the token output and information for the passed ids.
	GetTokenOutputsAndMeta(ctx context.Context, ids []*token.ID) ([][]byte, [][]byte, []token.Format, error)
	// GetTokens returns the list of tokens with their respective vault keys
	GetTokens(inputs ...*token.ID) ([]*token.Token, error)
	// WhoDeletedTokens returns info about who deleted the passed tokens.
	// The bool array is an indicator used to tell if the token at a given position has been deleted or not
	WhoDeletedTokens(inputs ...*token.ID) ([]string, []bool, error)
	// Balance returns the sun of the amounts, with 64 bits of precision, of the tokens with type and EID equal to those passed as arguments.
	Balance(id string, tokenType token.Type) (uint64, error)
}

type RecipientData added in v0.4.0

type RecipientData struct {
	// Identity is the identity of the token owner
	Identity Identity
	// AuditInfo contains private information Identity
	AuditInfo []byte
	// TokenMetadata contains public information related to the token to be assigned to this Recipient.
	TokenMetadata []byte
	// TokenMetadataAuditInfo contains private information TokenMetadata
	TokenMetadataAuditInfo []byte
}

RecipientData contains information about the identity of a token owner

type SerializedPublicParameters

type SerializedPublicParameters struct {
	// Identifier is the unique identifier of this public parameters.
	Identifier string
	// Raw is marshalled version of the public parameters.
	Raw []byte
}

SerializedPublicParameters is the serialized form of PublicParameters.

func (*SerializedPublicParameters) Deserialize

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

Deserialize deserializes the serialized public parameters.

type Serializer

type Serializer interface {
	// MarshalTokenRequestToSign marshals the to token request to a byte array representation on which a signature must be produced
	MarshalTokenRequestToSign(request *TokenRequest, meta *TokenRequestMetadata) ([]byte, error)
}

Serializer models the serialization needs of the Token Service

type ServiceOptions added in v0.4.0

type ServiceOptions struct {
	// Network is the name of the network
	Network string
	// Channel is the name of the channel, if meaningful for the underlying backend
	Channel string
	// Namespace is the namespace of the token
	Namespace string
	// PublicParamsFetcher is used to fetch the public parameters
	PublicParamsFetcher PublicParamsFetcher
	// PublicParams contains the public params to use to instantiate the driver
	PublicParams []byte
	// Params is used to store any application specific parameter
	Params map[string]interface{}
}

ServiceOptions is used to configure the service

func (ServiceOptions) ParamAsString added in v0.4.0

func (o ServiceOptions) ParamAsString(key string) (string, error)

ParamAsString returns the value bound to the passed key. If the key is not found, it returns the empty string. if the value bound to the passed key is not a string, it returns an error.

func (ServiceOptions) String added in v0.4.0

func (o ServiceOptions) String() string

type ServiceProvider added in v0.4.0

type ServiceProvider interface {
	// GetService returns an instance of the given type
	GetService(v interface{}) (interface{}, error)
}

ServiceProvider is used to return instances of a given type

type SetupAction

type SetupAction interface {
	GetSetupParameters() ([]byte, error)
}

SetupAction is the action used to update the public parameters

type SignatureProvider

type SignatureProvider interface {
	// HasBeenSignedBy returns true and the verified signature if the provider contains a valid signature for the passed identity and verifier
	HasBeenSignedBy(id Identity, verifier Verifier) ([]byte, error)
	// Signatures returns the signatures inside this provider
	Signatures() [][]byte
}

type Signer

type Signer interface {
	// Sign signs message bytes and returns the signature or an error on failure.
	Sign(message []byte) ([]byte, error)
}

Signer is an interface which wraps the Sign method.

type SigningIdentity

type SigningIdentity interface {
	// Sign signs message bytes and returns the signature or an error on failure.
	Sign(raw []byte) ([]byte, error)

	// Serialize serializes the signing identity
	Serialize() ([]byte, error)
}

SigningIdentity models a signing identity

type SpendableTokensIterator added in v0.4.0

type SpendableTokensIterator interface {
	Close()
	Next() (*token.UnspentTokenInWallet, error)
}

type TMSID added in v0.4.0

type TMSID struct {
	Network   string
	Channel   string
	Namespace string
}

TMSID models a TMS identifier

func (TMSID) Equal added in v0.4.0

func (t TMSID) Equal(tmsid TMSID) bool

func (TMSID) String added in v0.4.0

func (t TMSID) String() string

String returns a string representation of the TMSID

type TokenDriverName added in v0.4.0

type TokenDriverName string

type TokenDriverService added in v0.4.0

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

func GetTokenDriverService added in v0.4.0

func GetTokenDriverService(sp ServiceProvider) (*TokenDriverService, error)

func NewTokenDriverService added in v0.4.0

func NewTokenDriverService(factories []NamedFactory[Driver]) *TokenDriverService

func (*TokenDriverService) NewDefaultValidator added in v0.4.0

func (s *TokenDriverService) NewDefaultValidator(pp PublicParameters) (Validator, error)

func (*TokenDriverService) NewTokenService added in v0.4.0

func (s *TokenDriverService) NewTokenService(tmsID TMSID, publicParams []byte) (TokenManagerService, error)

func (TokenDriverService) PublicParametersFromBytes added in v0.4.0

func (s TokenDriverService) PublicParametersFromBytes(params []byte) (PublicParameters, error)

PublicParametersFromBytes unmarshals the bytes to a driver.PublicParameters instance. The passed bytes are expected to encode a driver.SerializedPublicParameters instance. If no driver is registered for the public params' identifier, it returns an error.

type TokenIDSer

type TokenIDSer struct {
	TxId  string
	Index int
}

type TokenManagerService

type TokenManagerService interface {
	IssueService() IssueService
	TransferService() TransferService
	TokensService() TokensService
	AuditorService() AuditorService
	CertificationService() CertificationService
	Deserializer() Deserializer
	Serializer() Serializer
	IdentityProvider() IdentityProvider
	Validator() (Validator, error)
	PublicParamsManager() PublicParamsManager
	Configuration() Configuration
	WalletService() WalletService
	Authorization() Authorization
	// Done releases all the resources allocated by this service
	Done() error
}

TokenManagerService is the entry point of the Driver API and gives access to the rest of the API

type TokenManagerServiceProvider

type TokenManagerServiceProvider interface {
	// GetTokenManagerService returns a TokenManagerService instance for the passed parameters
	// If a TokenManagerService is not available, it creates one.
	GetTokenManagerService(opts ServiceOptions) (TokenManagerService, error)

	// NewTokenManagerService returns a new TokenManagerService instance for the passed parameters
	NewTokenManagerService(opts ServiceOptions) (TokenManagerService, error)

	Update(options ServiceOptions) error

	Configurations() ([]Configuration, error)
}

type TokenRequest

type TokenRequest struct {
	Issues            [][]byte
	Transfers         [][]byte
	Signatures        [][]byte
	AuditorSignatures [][]byte
}

TokenRequest is a collection of Token Action: Issues, to create new Tokens; Transfers, to manipulate Tokens (e.g., transfer ownership or redeem) The actions in the collection are independent. An action cannot spend tokens created by another action in the same Token Request. In addition, actions comes with a set of Witnesses to verify the right to spend or the right to issue a given token

func (*TokenRequest) Bytes

func (r *TokenRequest) Bytes() ([]byte, error)

func (*TokenRequest) FromBytes

func (r *TokenRequest) FromBytes(raw []byte) error

type TokenRequestMetadata

type TokenRequestMetadata struct {
	// Issues is the list of issue actions metadata
	Issues []IssueMetadata
	// Transfers is the list of transfer actions metadata
	Transfers []TransferMetadata
	// Application enables attaching more info to the TokenRequestMetadata
	Application map[string][]byte
}

TokenRequestMetadata is a collection of actions metadata

func (*TokenRequestMetadata) Bytes

func (m *TokenRequestMetadata) Bytes() ([]byte, error)

func (*TokenRequestMetadata) FromBytes

func (m *TokenRequestMetadata) FromBytes(raw []byte) error

func (*TokenRequestMetadata) GetTokenInfo

func (m *TokenRequestMetadata) GetTokenInfo(tokenRaw []byte) []byte

GetTokenInfo returns the OutputsMetadata that matches the given token

type TokensService added in v0.4.0

type TokensService interface {
	// SupportedTokenFormats returns the supported token formats
	SupportedTokenFormats() []token.Format

	// Deobfuscate processes the passed output and metadata to derive a token.Token, its issuer (if any), and its token format
	Deobfuscate(output []byte, outputMetadata []byte) (*token.Token, Identity, token.Format, error)

	// ExtractMetadata extracts from the given token request metadata the metadata to the given target
	ExtractMetadata(meta *TokenRequestMetadata, target []byte) ([]byte, error)
}

type TransferAction

type TransferAction interface {
	// Serialize returns the serialized version of the action
	Serialize() ([]byte, error)
	// NumOutputs returns the number of outputs of the action
	NumOutputs() int
	// GetSerializedOutputs returns the serialized outputs of the action
	GetSerializedOutputs() ([][]byte, error)
	// GetOutputs returns the outputs of the action
	GetOutputs() []Output
	// IsRedeemAt returns true if the output is a redeem output at the passed index
	IsRedeemAt(index int) bool
	// SerializeOutputAt returns the serialized output at the passed index
	SerializeOutputAt(index int) ([]byte, error)
	// GetInputs returns the identifiers of the inputs in the action.
	GetInputs() []*token.ID
	// GetSerializedInputs returns the serialized inputs of the action
	GetSerializedInputs() ([][]byte, error)
	// GetSerialNumbers returns the serial numbers of the inputs if this action supports graph hiding
	GetSerialNumbers() []string
	// IsGraphHiding returns true if the action is graph hiding
	IsGraphHiding() bool
	// GetMetadata returns the action's metadata
	GetMetadata() map[string][]byte
}

TransferAction is the action used to transfer tokens

type TransferMetadata

type TransferMetadata struct {
	// TokenIDs is the list of TokenIDs spent by this action
	TokenIDs []*token.ID
	// Senders is the list of senders
	Senders []Identity
	// SendersAuditInfos, for each sender we have audit info to recover the enrollment ID of the sender
	SenderAuditInfos [][]byte

	// Outputs is the list of outputs created by this transfer action
	Outputs [][]byte
	// OutputsMetadata, for each output we have an OutputsMetadata entry that contains secrets to de-obfuscate the output
	OutputsMetadata [][]byte
	// OutputAuditInfos, for each output owner we have audit info
	OutputAuditInfos [][]byte
	// Receivers is the list of receivers
	Receivers []Identity
	// ReceiversAuditInfos, for each receiver we have audit info to recover the enrollment ID of the receiver
	ReceiverAuditInfos [][]byte
	// ReceiverIsSender indicates if the receiver is a sender in this very same action
	ReceiverIsSender []bool

	// ExtraSigners is the list of extra identities that are not part of the transfer action per se
	// but needs to sign the request
	ExtraSigners []Identity
}

TransferMetadata contains the metadata of a transfer action For each TokenID there is a sender with its audit info to recover its enrollment ID, For each Output there is: - A OutputsMetadata entry to de-obfuscate the output; - A Receiver identity; - A ReceiverAuditInfo entry to recover the enrollment ID of the receiver - A Flag to indicate if the receiver is a sender in this very same action

func (*TransferMetadata) TokenIDAt

func (tm *TransferMetadata) TokenIDAt(index int) *token.ID

TokenIDAt returns the TokenID at the given index. It returns nil if the index is out of bounds.

type TransferMetadataSer

type TransferMetadataSer struct {
	TokenIDs           []TokenIDSer
	Outputs            [][]byte
	OutputAuditInfos   [][]byte
	OutputsMetadata    [][]byte
	Senders            []Identity
	SenderAuditInfos   [][]byte
	Receivers          []Identity
	ReceiverIsSender   []bool
	ReceiverAuditInfos [][]byte
	ExtraSigners       []Identity
}

type TransferOptions

type TransferOptions struct {
	// Attributes is a container of generic options that might be driver specific
	Attributes map[interface{}]interface{}
}

TransferOptions models the options that can be passed to the transfer command

type TransferService

type TransferService interface {
	// Transfer generates a TransferAction that spend the passed token ids and created the passed outputs.
	// In addition, a set of options can be specified to further customize the transfer command.
	// The function returns an TransferAction and the associated metadata.
	Transfer(ctx context.Context, txID string, wallet OwnerWallet, ids []*token2.ID, Outputs []*token2.Token, opts *TransferOptions) (TransferAction, *TransferMetadata, error)

	// VerifyTransfer checks the well-formedness of the passed TransferAction with the respect to the passed output metadata
	VerifyTransfer(tr TransferAction, tokenInfos [][]byte) error

	// DeserializeTransferAction deserializes the passed bytes into an TransferAction
	DeserializeTransferAction(raw []byte) (TransferAction, error)
}

TransferService models the token transfer service

type TxStatus added in v0.4.0

type TxStatus = int

TxStatus is the status of a transaction

const (
	// Unknown is the status of a transaction that is unknown
	Unknown TxStatus = iota
	// Pending is the status of a transaction that has been submitted to the ledger
	Pending
	// Confirmed is the status of a transaction that has been confirmed by the ledger
	Confirmed
	// Deleted is the status of a transaction that has been deleted due to a failure to commit
	Deleted
)

type UnspentTokensIterator

type UnspentTokensIterator interface {
	Close()
	Next() (*token.UnspentToken, error)
}

type ValidationAttributeID added in v0.4.0

type ValidationAttributeID = string

ValidationAttributeID is the type of validation attribute identifier

type ValidationAttributes added in v0.4.0

type ValidationAttributes = map[ValidationAttributeID][]byte

ValidationAttributes is a map containing attributes generated during validation

type Validator

type Validator interface {
	// UnmarshalActions returns the actions contained in the serialized token request
	UnmarshalActions(raw []byte) ([]interface{}, error)
	// VerifyTokenRequestFromRaw verifies the passed marshalled token request against the passed ledger and anchor.
	// The function returns additionally a map that contains information about the token request. The content of this map
	// is driver-dependant
	VerifyTokenRequestFromRaw(ctx context.Context, getState GetStateFnc, anchor string, raw []byte) ([]interface{}, ValidationAttributes, error)
}

Validator models a token request validator

type ValidatorLedger added in v0.4.0

type ValidatorLedger interface {
	GetState(id token.ID) ([]byte, error)
}

type Vault

type Vault interface {
	QueryEngine() QueryEngine
	CertificationStorage() CertificationStorage
}

type Verifier

type Verifier interface {
	// Verify verifies the signature over the message bytes and returns nil if the signature is valid and an error otherwise.
	Verify(message, sigma []byte) error
}

Verifier is an interface which wraps the Verify method.

type Wallet

type Wallet interface {
	// ID returns the ID of this wallet
	ID() string

	// Contains returns true if the passed identity belongs to this wallet
	Contains(identity Identity) bool

	// ContainsToken returns true if the passed token is owned by this wallet
	ContainsToken(token *token.UnspentToken) bool

	// GetSigner returns the Signer bound to the passed identity
	GetSigner(identity Identity) (Signer, error)
}

Wallet models a generic wallet

type WalletLookupID added in v0.4.0

type WalletLookupID = any

WalletLookupID defines the type of identifiers that can be used to retrieve a given wallet. It can be a string, as the name of the wallet, or an identity contained in that wallet. Ultimately, it is the token driver to decide which types are allowed.

type WalletService

type WalletService interface {
	// RegisterRecipientIdentity registers the passed recipient identity together with the associated audit information
	RegisterRecipientIdentity(data *RecipientData) error

	// GetAuditInfo retrieves the audit information for the passed identity
	GetAuditInfo(id Identity) ([]byte, error)

	// GetEnrollmentID extracts the enrollment id from the passed audit information
	GetEnrollmentID(identity Identity, auditInfo []byte) (string, error)

	// GetRevocationHandle extracts the revocation handler from the passed audit information
	GetRevocationHandle(identity Identity, auditInfo []byte) (string, error)

	// GetEIDAndRH returns both enrollment ID and revocation handle
	GetEIDAndRH(identity Identity, auditInfo []byte) (string, string, error)

	// Wallet returns the wallet bound to the passed identity, if any is available
	Wallet(identity Identity) Wallet

	// RegisterOwnerIdentity registers an owner long-term identity
	RegisterOwnerIdentity(config IdentityConfiguration) error

	// RegisterIssuerIdentity registers an issuer long-term wallet
	RegisterIssuerIdentity(config IdentityConfiguration) error

	// OwnerWalletIDs returns the list of owner wallet identifiers
	OwnerWalletIDs() ([]string, error)

	// OwnerWallet returns an instance of the OwnerWallet interface bound to the passed id.
	// The id can be: the wallet identifier or a unique id of a view identity belonging to the wallet.
	OwnerWallet(id WalletLookupID) (OwnerWallet, error)

	// IssuerWallet returns an instance of the IssuerWallet interface bound to the passed id.
	// The id can be: the wallet identifier or a unique id of a view identity belonging to the wallet.
	IssuerWallet(id WalletLookupID) (IssuerWallet, error)

	// AuditorWallet returns an instance of the AuditorWallet interface bound to the passed id.
	// The id can be: the wallet identifier or a unique id of a view identity belonging to the wallet.
	AuditorWallet(id WalletLookupID) (AuditorWallet, error)

	// CertifierWallet returns an instance of the CertifierWallet interface bound to the passed id.
	// The id can be: the wallet identifier or a unique id of a view identity belonging to the wallet.
	CertifierWallet(id WalletLookupID) (CertifierWallet, error)

	// SpentIDs returns the spend ids for the passed token ids
	SpentIDs(ids ...*token.ID) ([]string, error)
}

WalletService models the wallet service that handles issuer, recipient, auditor and certifier wallets

type WalletServiceFactory added in v0.4.0

type WalletServiceFactory interface {
	PPReader
	// NewWalletService returns an instance of the WalletService interface for the passed arguments
	NewWalletService(tmsConfig Config, params PublicParameters) (WalletService, error)
}

type WalletServiceFactoryService added in v0.4.0

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

func NewWalletServiceFactoryService added in v0.4.0

func NewWalletServiceFactoryService(fs ...NamedFactory[WalletServiceFactory]) *WalletServiceFactoryService

func (*WalletServiceFactoryService) NewWalletService added in v0.4.0

func (s *WalletServiceFactoryService) NewWalletService(tmsConfig Config, ppRaw []byte) (WalletService, error)

func (WalletServiceFactoryService) PublicParametersFromBytes added in v0.4.0

func (s WalletServiceFactoryService) PublicParametersFromBytes(params []byte) (PublicParameters, error)

PublicParametersFromBytes unmarshals the bytes to a driver.PublicParameters instance. The passed bytes are expected to encode a driver.SerializedPublicParameters instance. If no driver is registered for the public params' identifier, it returns an error.

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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