common

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	TokenRequestToSign     driver.ValidationAttributeID = "trs"
	TokenRequestSignatures driver.ValidationAttributeID = "sigs"
)

Variables

This section is empty.

Functions

func AuditingSignaturesValidate added in v0.5.0

func AuditingSignaturesValidate[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer](ctx *Context[P, T, TA, IA, DS]) error

func IsAnyNil added in v0.5.0

func IsAnyNil[T any](args ...*T) bool

func SelectIssuerForRedeem added in v0.5.0

func SelectIssuerForRedeem(issuers []driver.Identity, opts *driver.TransferOptions) (driver.Identity, error)

SelectIssuerForRedeem return the issuer's public key to use for a redeem. If opts specify an FSC issuer identity, then we expect to find the opts also the public key to add in the transfer action. Otherwise, the first public key in the public params is used.

Types

type ActionDeserializer added in v0.4.0

type ActionDeserializer[TA driver.TransferAction, IA driver.IssueAction] interface {
	DeserializeActions(tr *driver.TokenRequest) ([]IA, []TA, error)
}

type AuditMatcherProvider added in v0.4.0

type AuditMatcherProvider interface {
	MatcherDeserializer
	MatchIdentity(id driver.Identity, ai []byte) error
	GetAuditInfo(ctx context.Context, id driver.Identity, p driver.AuditInfoProvider) ([]byte, error)
}

AuditMatcherProvider provides audit related deserialization functionalities

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 and any additional owner identifier, if supported.
	// It is possible that the wallet ID is empty and the additional owner identifier list is not.
	IsMine(ctx context.Context, tok *token2.Token) (string, []string, 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(ctx context.Context, issuer token.Identity, tok *token2.Token) bool
}

type AuthorizationMultiplexer added in v0.4.0

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

AuthorizationMultiplexer iterates over multiple authorization checker

func NewAuthorizationMultiplexer added in v0.4.0

func NewAuthorizationMultiplexer(ownerships ...Authorization) *AuthorizationMultiplexer

NewAuthorizationMultiplexer returns a new AuthorizationMultiplexer for the passed ownership checkers

func (*AuthorizationMultiplexer) AmIAnAuditor added in v0.4.0

func (o *AuthorizationMultiplexer) AmIAnAuditor() bool

AmIAnAuditor returns true it there exists an authorization checker that returns true

func (*AuthorizationMultiplexer) IsMine added in v0.4.0

IsMine returns true it there exists an authorization checker that returns true

func (*AuthorizationMultiplexer) Issued added in v0.4.0

func (o *AuthorizationMultiplexer) Issued(ctx context.Context, issuer token.Identity, tok *token2.Token) bool

func (*AuthorizationMultiplexer) OwnerType added in v0.4.0

func (o *AuthorizationMultiplexer) OwnerType(raw []byte) (string, []byte, error)

OwnerType returns the type of owner (e.g. 'idemix' or 'htlc') and the identity bytes

type Backend

type Backend struct {
	Logger logging.Logger
	// Ledger to access the ledger state
	Ledger driver.GetStateFnc
	// signed Message
	Message []byte
	// Cursor is used to iterate over the signatures
	Cursor int
	// signatures on Message
	Sigs [][]byte
}

func NewBackend

func NewBackend(logger logging.Logger, ledger driver.GetStateFnc, message []byte, sigs [][]byte) *Backend

func (*Backend) GetState

func (b *Backend) GetState(id token.ID) ([]byte, error)

func (*Backend) HasBeenSignedBy

func (b *Backend) HasBeenSignedBy(id driver.Identity, verifier driver.Verifier) ([]byte, error)

HasBeenSignedBy checks if a given Message has been signed by the signing identity matching the passed verifier

func (*Backend) Signatures

func (b *Backend) Signatures() [][]byte

type Context added in v0.4.0

type Context[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] struct {
	Logger            logging.Logger
	PP                P
	Anchor            driver.TokenRequestAnchor
	TokenRequest      *driver.TokenRequest
	Deserializer      DS
	SignatureProvider driver.SignatureProvider
	Signatures        [][]byte
	InputTokens       []T
	TransferAction    TA
	IssueAction       IA
	Ledger            driver.Ledger
	MetadataCounter   map[MetadataCounterID]int
	Attributes        driver.ValidationAttributes
}

func (*Context[P, T, TA, IA, DS]) CountMetadataKey added in v0.4.0

func (c *Context[P, T, TA, IA, DS]) CountMetadataKey(key string)

type Deserializer added in v0.4.0

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

Deserializer deserializes verifiers associated with issuers, owners, and auditors

func NewDeserializer added in v0.4.0

func NewDeserializer(
	identityType string,
	auditorDeserializer VerifierDeserializer,
	ownerDeserializer VerifierDeserializer,
	issuerDeserializer VerifierDeserializer,
	auditMatcherProvider AuditMatcherProvider,
	recipientExtractor RecipientExtractor,
) *Deserializer

func (*Deserializer) GetAuditInfo added in v0.5.0

func (d *Deserializer) GetAuditInfo(ctx context.Context, id driver.Identity, p driver.AuditInfoProvider) ([]byte, error)

func (*Deserializer) GetAuditInfoMatcher added in v0.5.0

func (d *Deserializer) GetAuditInfoMatcher(owner driver.Identity, auditInfo []byte) (driver.Matcher, error)

func (*Deserializer) GetAuditorVerifier added in v0.4.0

func (d *Deserializer) GetAuditorVerifier(id driver.Identity) (driver.Verifier, error)

func (*Deserializer) GetIssuerVerifier added in v0.4.0

func (d *Deserializer) GetIssuerVerifier(id driver.Identity) (driver.Verifier, error)

func (*Deserializer) GetOwnerVerifier added in v0.4.0

func (d *Deserializer) GetOwnerVerifier(id driver.Identity) (driver.Verifier, error)

func (*Deserializer) MatchIdentity added in v0.5.0

func (d *Deserializer) MatchIdentity(id driver.Identity, ai []byte) error

func (*Deserializer) Recipients added in v0.4.0

func (d *Deserializer) Recipients(id driver.Identity) ([]driver.Identity, error)

type IdentityTokenAndMetadataDeserializer added in v0.4.0

type IdentityTokenAndMetadataDeserializer struct{}

func (IdentityTokenAndMetadataDeserializer) DeserializeMetadata added in v0.4.0

func (i IdentityTokenAndMetadataDeserializer) DeserializeMetadata(bytes []byte) ([]byte, error)

func (IdentityTokenAndMetadataDeserializer) DeserializeToken added in v0.4.0

func (i IdentityTokenAndMetadataDeserializer) DeserializeToken(bytes []byte) ([]byte, error)

type LedgerToken added in v0.4.0

type LedgerToken interface {
	GetOwner() []byte
}

type LoadedToken added in v0.4.0

type LoadedToken[T any, M any] struct {
	TokenFormat token.Format
	Token       T
	Metadata    M
}

type MatcherDeserializer added in v0.5.0

type MatcherDeserializer interface {
	GetAuditInfoMatcher(owner driver.Identity, auditInfo []byte) (driver.Matcher, error)
}

type MetadataCounterID added in v0.4.0

type MetadataCounterID = string

type MetadataDeserializer added in v0.4.0

type MetadataDeserializer[M any] interface {
	DeserializeMetadata([]byte) (M, error)
}

type PublicParametersManager added in v0.4.0

type PublicParametersManager[T driver.PublicParameters] interface {
	driver.PublicParamsManager
	PublicParams(ctx context.Context) T
}

type PublicParamsDeserializer added in v0.4.0

type PublicParamsDeserializer[T driver.PublicParameters] interface {
	DeserializePublicParams(raw []byte, name driver.TokenDriverName, version driver.TokenDriverVersion) (T, error)
}

type PublicParamsManager added in v0.4.0

type PublicParamsManager[T driver.PublicParameters] struct {

	// label of the public params
	DriverName    driver.TokenDriverName
	DriverVersion driver.TokenDriverVersion
	// contains filtered or unexported fields
}

func NewPublicParamsManager added in v0.4.0

func NewPublicParamsManager[T driver.PublicParameters](
	PublicParamsDeserializer PublicParamsDeserializer[T],
	driverName driver.TokenDriverName,
	driverVersion driver.TokenDriverVersion,
	ppRaw []byte,
) (*PublicParamsManager[T], error)

func NewPublicParamsManagerFromParams added in v0.4.0

func NewPublicParamsManagerFromParams[T driver.PublicParameters](pp T) (*PublicParamsManager[T], error)

func (*PublicParamsManager[T]) NewCertifierKeyPair added in v0.4.0

func (v *PublicParamsManager[T]) NewCertifierKeyPair() ([]byte, []byte, error)

func (*PublicParamsManager[T]) PublicParameters added in v0.4.0

func (v *PublicParamsManager[T]) PublicParameters() driver.PublicParameters

func (*PublicParamsManager[T]) PublicParams added in v0.4.0

func (v *PublicParamsManager[T]) PublicParams(ctx context.Context) T

func (*PublicParamsManager[T]) PublicParamsHash added in v0.4.0

func (v *PublicParamsManager[T]) PublicParamsHash() driver.PPHash

type RecipientExtractor added in v0.4.0

type RecipientExtractor interface {
	Recipients(id driver.Identity) ([]driver.Identity, error)
}

RecipientExtractor extracts the recipients from an identity

type Service added in v0.4.0

type Service[T driver.PublicParameters] struct {
	Logger                  logging.Logger
	PublicParametersManager PublicParametersManager[T]
	// contains filtered or unexported fields
}

func NewTokenService added in v0.4.0

func NewTokenService[T driver.PublicParameters](
	logger logging.Logger,
	ws *wallet.Service,
	publicParametersManager PublicParametersManager[T],
	identityProvider driver.IdentityProvider,
	deserializer driver.Deserializer,
	configManager driver.Configuration,
	certificationService driver.CertificationService,
	issueService driver.IssueService,
	transferService driver.TransferService,
	auditorService driver.AuditorService,
	tokensService driver.TokensService,
	tokensUpgradeService driver.TokensUpgradeService,
	authorization driver.Authorization,
) (*Service[T], error)

func (*Service[T]) AuditorService added in v0.4.0

func (s *Service[T]) AuditorService() driver.AuditorService

func (*Service[T]) Authorization added in v0.4.0

func (s *Service[T]) Authorization() driver.Authorization

func (*Service[T]) CertificationService added in v0.4.0

func (s *Service[T]) CertificationService() driver.CertificationService

func (*Service[T]) Configuration added in v0.4.0

func (s *Service[T]) Configuration() driver.Configuration

Configuration returns the configuration manager associated with the service

func (*Service[T]) Deserializer added in v0.4.0

func (s *Service[T]) Deserializer() driver.Deserializer

func (*Service[T]) Done added in v0.4.0

func (s *Service[T]) Done() error

Done releases all the resources allocated by this service

func (*Service[T]) IdentityProvider added in v0.4.0

func (s *Service[T]) IdentityProvider() driver.IdentityProvider

IdentityProvider returns the identity provider associated with the service

func (*Service[T]) IssueService added in v0.4.0

func (s *Service[T]) IssueService() driver.IssueService

func (*Service[T]) PublicParamsManager added in v0.4.0

func (s *Service[T]) PublicParamsManager() driver.PublicParamsManager

PublicParamsManager returns the manager of the public parameters associated with the service

func (*Service[T]) TokensService added in v0.4.0

func (s *Service[T]) TokensService() driver.TokensService

func (*Service[T]) TokensUpgradeService added in v0.5.0

func (s *Service[T]) TokensUpgradeService() driver.TokensUpgradeService

func (*Service[T]) TransferService added in v0.4.0

func (s *Service[T]) TransferService() driver.TransferService

func (*Service[T]) WalletService added in v0.4.0

func (s *Service[T]) WalletService() driver.WalletService

type TokenAndMetadataDeserializer added in v0.4.0

type TokenAndMetadataDeserializer[T any, M any] interface {
	TokenDeserializer[T]
	MetadataDeserializer[M]
}

type TokenCertificationStorage added in v0.4.0

type TokenCertificationStorage interface {
	GetCertifications(ctx context.Context, ids []*token.ID) ([][]byte, error)
}

type TokenDeserializer added in v0.4.0

type TokenDeserializer[T any] interface {
	DeserializeToken([]byte) (T, error)
}

type TokenVault added in v0.4.0

type TokenVault interface {
	IsPending(ctx context.Context, id *token.ID) (bool, error)
	GetTokenOutputsAndMeta(ctx context.Context, ids []*token.ID) ([][]byte, [][]byte, []token.Format, error)
	GetTokenOutputs(ctx context.Context, ids []*token.ID, callback driver.QueryCallbackFunc) error
	UnspentTokensIteratorBy(ctx context.Context, id string, tokenType token.Type) (driver.UnspentTokensIterator, error)
	ListHistoryIssuedTokens(ctx context.Context) (*token.IssuedTokens, error)
	PublicParams(ctx context.Context) ([]byte, error)
	Balance(ctx context.Context, id string, tokenType token.Type) (uint64, error)
}

type ValidateAuditingFunc added in v0.5.0

type ValidateAuditingFunc[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] func(ctx *Context[P, T, TA, IA, DS]) error

type ValidateIssueFunc added in v0.4.0

type ValidateIssueFunc[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] func(ctx *Context[P, T, TA, IA, DS]) error

type ValidateTransferFunc added in v0.4.0

type ValidateTransferFunc[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] func(ctx *Context[P, T, TA, IA, DS]) error

type Validator added in v0.4.0

type Validator[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] struct {
	Logger             logging.Logger
	PublicParams       P
	Deserializer       DS
	ActionDeserializer ActionDeserializer[TA, IA]

	AuditingValidators []ValidateAuditingFunc[P, T, TA, IA, DS]
	TransferValidators []ValidateTransferFunc[P, T, TA, IA, DS]
	IssueValidators    []ValidateIssueFunc[P, T, TA, IA, DS]
}

func NewValidator added in v0.4.0

func NewValidator[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer](
	Logger logging.Logger,
	publicParams P,
	deserializer DS,
	actionDeserializer ActionDeserializer[TA, IA],
	transferValidators []ValidateTransferFunc[P, T, TA, IA, DS],
	issueValidators []ValidateIssueFunc[P, T, TA, IA, DS],
	auditingValidators []ValidateAuditingFunc[P, T, TA, IA, DS],
) *Validator[P, T, TA, IA, DS]

func (*Validator[P, T, TA, IA, DS]) UnmarshalActions added in v0.4.0

func (v *Validator[P, T, TA, IA, DS]) UnmarshalActions(raw []byte) ([]interface{}, error)

func (*Validator[P, T, TA, IA, DS]) VerifyAuditing added in v0.5.0

func (v *Validator[P, T, TA, IA, DS]) VerifyAuditing(
	anchor driver.TokenRequestAnchor,
	tokenRequest *driver.TokenRequest,
	ledger driver.Ledger,
	signatureProvider driver.SignatureProvider,
	attributes driver.ValidationAttributes,
) error

func (*Validator[P, T, TA, IA, DS]) VerifyIssue added in v0.5.0

func (v *Validator[P, T, TA, IA, DS]) VerifyIssue(
	anchor driver.TokenRequestAnchor,
	tokenRequest *driver.TokenRequest,
	action IA,
	ledger driver.Ledger,
	signatureProvider driver.SignatureProvider,
	attributes driver.ValidationAttributes,
) error

func (*Validator[P, T, TA, IA, DS]) VerifyTokenRequest added in v0.4.0

func (v *Validator[P, T, TA, IA, DS]) VerifyTokenRequest(
	ledger driver.Ledger,
	signatureProvider driver.SignatureProvider,
	anchor driver.TokenRequestAnchor,
	tr *driver.TokenRequest,
	attributes driver.ValidationAttributes,
) ([]interface{}, driver.ValidationAttributes, error)

func (*Validator[P, T, TA, IA, DS]) VerifyTokenRequestFromRaw added in v0.4.0

func (v *Validator[P, T, TA, IA, DS]) VerifyTokenRequestFromRaw(ctx context.Context, getState driver.GetStateFnc, anchor driver.TokenRequestAnchor, raw []byte) ([]interface{}, driver.ValidationAttributes, error)

func (*Validator[P, T, TA, IA, DS]) VerifyTransfer added in v0.5.0

func (v *Validator[P, T, TA, IA, DS]) VerifyTransfer(
	anchor driver.TokenRequestAnchor,
	tokenRequest *driver.TokenRequest,
	action TA,
	ledger driver.Ledger,
	signatureProvider driver.SignatureProvider,
	attributes driver.ValidationAttributes,
) error

type VaultLedgerTokenAndMetadataLoader added in v0.4.0

type VaultLedgerTokenAndMetadataLoader[T any, M any] struct {
	TokenVault   TokenVault
	Deserializer TokenAndMetadataDeserializer[T, M]
}

func NewVaultLedgerTokenAndMetadataLoader added in v0.4.0

func NewVaultLedgerTokenAndMetadataLoader[T any, M any](tokenVault TokenVault, deserializer TokenAndMetadataDeserializer[T, M]) *VaultLedgerTokenAndMetadataLoader[T, M]

func (*VaultLedgerTokenAndMetadataLoader[T, M]) LoadTokens added in v0.4.0

func (s *VaultLedgerTokenAndMetadataLoader[T, M]) LoadTokens(ctx context.Context, ids []*token.ID) ([]LoadedToken[T, M], error)

LoadTokens takes an array of token identifiers (txID, index) and returns the keys in the vault matching the token identifiers, the corresponding zkatdlog tokens, the information of the tokens in clear text and the identities of their owners LoadToken returns an error in case of failure

type VaultLedgerTokenLoader added in v0.4.0

type VaultLedgerTokenLoader[T any] struct {
	Logger       logging.Logger
	TokenVault   TokenVault
	Deserializer TokenDeserializer[T]

	// Variables used to control retry condition
	NumRetries int
	RetryDelay time.Duration
}

func NewLedgerTokenLoader added in v0.4.0

func NewLedgerTokenLoader[T any](logger logging.Logger, _ trace.TracerProvider, tokenVault TokenVault, deserializer TokenDeserializer[T]) *VaultLedgerTokenLoader[T]

func (*VaultLedgerTokenLoader[T]) GetTokenOutputs added in v0.4.0

func (s *VaultLedgerTokenLoader[T]) GetTokenOutputs(ctx context.Context, ids []*token.ID) (map[string]T, error)

GetTokenOutputs takes an array of token identifiers (txID, index) and returns the corresponding token outputs

type VaultTokenCertificationLoader added in v0.4.0

type VaultTokenCertificationLoader struct {
	TokenCertificationStorage TokenCertificationStorage
}

func (*VaultTokenCertificationLoader) GetCertifications added in v0.4.0

func (s *VaultTokenCertificationLoader) GetCertifications(ctx context.Context, ids []*token.ID) ([][]byte, error)

type VaultTokenInfoLoader added in v0.4.0

type VaultTokenInfoLoader[M any] struct {
	TokenVault   driver.QueryEngine
	Deserializer MetadataDeserializer[M]
}

func NewVaultTokenInfoLoader added in v0.4.0

func NewVaultTokenInfoLoader[M any](tokenVault driver.QueryEngine, deserializer MetadataDeserializer[M]) *VaultTokenInfoLoader[M]

func (*VaultTokenInfoLoader[M]) GetTokenInfos added in v0.4.0

func (s *VaultTokenInfoLoader[M]) GetTokenInfos(ctx context.Context, ids []*token.ID) ([]M, error)

type VaultTokenLoader added in v0.4.0

type VaultTokenLoader struct {
	TokenVault driver.QueryEngine
}

func NewVaultTokenLoader added in v0.4.0

func NewVaultTokenLoader(tokenVault driver.QueryEngine) *VaultTokenLoader

func (*VaultTokenLoader) GetTokens added in v0.4.0

func (s *VaultTokenLoader) GetTokens(ctx context.Context, ids []*token.ID) ([]*token.Token, error)

GetTokens takes an array of token identifiers (txID, index) and returns the keys of the identified tokens in the vault and the content of the tokens

type VerifierDeserializer added in v0.4.0

type VerifierDeserializer interface {
	DeserializeVerifier(id driver.Identity) (driver.Verifier, error)
}

VerifierDeserializer is the interface for verifiers' deserializer. A verifier checks the validity of a signature against the identity associated with the verifier

type WalletBasedAuthorization added in v0.4.0

type WalletBasedAuthorization struct {
	Logger           logging.Logger
	PublicParameters driver.PublicParameters
	WalletService    driver.WalletService
	// contains filtered or unexported fields
}

WalletBasedAuthorization is a wallet-based authorization implementation

func NewTMSAuthorization added in v0.4.0

func NewTMSAuthorization(logger logging.Logger, publicParameters driver.PublicParameters, walletService driver.WalletService) *WalletBasedAuthorization

func (*WalletBasedAuthorization) AmIAnAuditor added in v0.4.0

func (w *WalletBasedAuthorization) AmIAnAuditor() 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.

func (*WalletBasedAuthorization) IsMine added in v0.4.0

IsMine returns true if the passed token is owned by an owner wallet. It returns the ID of the owner wallet and no additional owner identifiers.

func (*WalletBasedAuthorization) Issued added in v0.4.0

func (w *WalletBasedAuthorization) Issued(ctx context.Context, issuer token.Identity, tok *token2.Token) bool

Directories

Path Synopsis
encoding
pp

Jump to

Keyboard shortcuts

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