token

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Overview

Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	TransferMetadataPrefix = "TransferMetadataPrefix"
)

Variables

View Source
var (
	// SelectorInsufficientFunds is returned when funds are not sufficient to cover the request
	SelectorInsufficientFunds = errors.New("insufficient funds")
	// SelectorSufficientButLockedFunds is returned when funds are sufficient to cover the request, but some tokens are locked
	// by other transactions
	SelectorSufficientButLockedFunds = errors.New("sufficient but partially locked funds")
	// SelectorSufficientButNotCertifiedFunds is returned when funds are sufficient to cover the request, but some tokens
	// are not yet certified and therefore cannot be used.
	SelectorSufficientButNotCertifiedFunds = errors.New("sufficient but partially not certified")
	// SelectorSufficientFundsButConcurrencyIssue is returned when funds are sufficient to cover the request, but
	// concurrency issues does not make some of the selected tokens available.
	SelectorSufficientFundsButConcurrencyIssue = errors.New("sufficient funds but concurrency issue")
)

Functions

func CompileListTokensOption

func CompileListTokensOption(opts ...ListTokensOption) (*driver.ListTokensOptions, error)

func NewServicesFromPublicParams

func NewServicesFromPublicParams(params []byte) (*PublicParametersManager, *Validator, error)

NewServicesFromPublicParams uses the passed marshalled public parameters to create an instance of PublicParametersManager and a new instance of Validator.

Types

type AuditRecord

type AuditRecord struct {
	Anchor  string
	Inputs  *InputStream
	Outputs *OutputStream
}

AuditRecord models the audit record returned by the audit command It contains the token request's anchor, inputs (with Type and Quantity), and outputs

type AuditorWallet

type AuditorWallet struct {
	*Wallet
	// contains filtered or unexported fields
}

AuditorWallet models the wallet of an auditor

func (*AuditorWallet) GetAuditorIdentity

func (a *AuditorWallet) GetAuditorIdentity() (view.Identity, error)

GetAuditorIdentity returns the auditor identity. This can be a long term identity or a pseudonym depending on the underlying token driver.

func (*AuditorWallet) GetSigner

func (a *AuditorWallet) GetSigner(id view.Identity) (driver.Signer, error)

GetSigner returns the signer bound to the passed auditor identity.

type CertificationClient

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

CertificationClient is the client side of the certification process

func (*CertificationClient) IsCertified

func (c *CertificationClient) IsCertified(id *token2.ID) bool

IsCertified returns true if the passed token id has been already certified, otherwise false

func (*CertificationClient) RequestCertification

func (c *CertificationClient) RequestCertification(ids ...*token2.ID) error

RequestCertification requests the certification of the passed token ids

type CertificationClientProvider

type CertificationClientProvider interface {
	// New returns a new CertificationClient instance for the passed inputs
	New(network string, channel string, namespace string, driver string) (driver.CertificationClient, error)
}

CertificationClientProvider provides instances of CertificationClient

type CertificationManager

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

CertificationManager manages token certifications as described by the paper [`Privacy-preserving auditable token payments in a permissioned blockchain system`]('https://eprint.iacr.org/2019/1058.pdf')

func (*CertificationManager) Certify

func (c *CertificationManager) Certify(wallet *CertifierWallet, ids []*token2.ID, tokens [][]byte, request []byte) ([][]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.

func (*CertificationManager) NewCertificationRequest

func (c *CertificationManager) NewCertificationRequest(ids []*token2.ID) ([]byte, error)

NewCertificationRequest creates a new certification request for the passed token ids

func (*CertificationManager) VerifyCertifications

func (c *CertificationManager) VerifyCertifications(ids []*token2.ID, certifications [][]byte) error

VerifyCertifications verfiies the certification of the passed token ids.

type CertifierWallet

type CertifierWallet struct {
	*Wallet
	// contains filtered or unexported fields
}

CertifierWallet models the wallet of a certifier

func (*CertifierWallet) GetCertifierIdentity

func (a *CertifierWallet) GetCertifierIdentity() (view.Identity, error)

GetCertifierIdentity returns the certifier identity. This can be a long term identity or a pseudonym depending on the underlying token driver.

func (*CertifierWallet) GetSigner

func (a *CertifierWallet) GetSigner(id view.Identity) (driver.Signer, error)

GetSigner returns the signer bound to the passed certifier identity.

type ConfigManager

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

ConfigManager manages the configuration of the token-sdk

func (*ConfigManager) Certifiers

func (m *ConfigManager) Certifiers() []string

Certifiers returns the list of certifier ids.

func (*ConfigManager) IsSet added in v0.2.0

func (m *ConfigManager) IsSet(key string) bool

IsSet checks to see if the key has been set in any of the data locations

func (*ConfigManager) UnmarshalKey added in v0.2.0

func (m *ConfigManager) UnmarshalKey(key string, rawVal interface{}) error

UnmarshalKey takes a single key and unmarshals it into a Struct

type Input

type Input struct {
	ActionIndex       int
	Id                *token2.ID
	Owner             view.Identity
	OwnerAuditInfo    []byte
	EnrollmentID      string
	RevocationHandler string
	Type              string
	Quantity          token2.Quantity
}

Input models an input of a token action

type InputStream

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

InputStream models a stream over a set of inputs (Input).

func NewInputStream

func NewInputStream(qs QueryService, inputs []*Input, precision uint64) *InputStream

NewInputStream creates a new InputStream for the passed inputs and query service.

func (*InputStream) At

func (is *InputStream) At(i int) *Input

At returns the input at the given index.

func (*InputStream) ByEnrollmentID

func (is *InputStream) ByEnrollmentID(id string) *InputStream

ByEnrollmentID filters by enrollment ID.

func (*InputStream) ByType

func (is *InputStream) ByType(tokenType string) *InputStream

ByType filters by token type.

func (*InputStream) Count

func (is *InputStream) Count() int

Count returns the number of inputs in the stream

func (*InputStream) EnrollmentIDs

func (is *InputStream) EnrollmentIDs() []string

EnrollmentIDs returns the enrollment IDs of the owners of the inputs. It might be empty, if not available.

func (*InputStream) Filter

func (is *InputStream) Filter(f func(t *Input) bool) *InputStream

Filter returns a new InputStream with only the inputs that satisfy the predicate

func (*InputStream) IDs

func (is *InputStream) IDs() []*token2.ID

IDs returns the IDs of the inputs.

func (*InputStream) IsAnyMine

func (is *InputStream) IsAnyMine() (bool, error)

IsAnyMine returns true if any of the inputs are mine

func (*InputStream) Owners

func (is *InputStream) Owners() *OwnerStream

Owners returns a list of identities that own the tokens in the stream

func (*InputStream) RevocationHandles added in v0.3.0

func (is *InputStream) RevocationHandles() []string

RevocationHandles returns the Revocation Handles of the owners of the inputs. It might be empty, if not available.

func (*InputStream) String

func (is *InputStream) String() string

String returns a string representation of the input stream

func (*InputStream) Sum

func (is *InputStream) Sum() *big.Int

Sum returns the sum of the quantities of the inputs.

func (*InputStream) TokenTypes

func (is *InputStream) TokenTypes() []string

TokenTypes returns the token types of the inputs.

type Issue

type Issue struct {
	// Issuer is the issuer of the tokens
	Issuer view.Identity
	// Receivers is the list of identities of the receivers
	Receivers []view.Identity
	// ExtraSigners is the list of extra identities that must sign the token request to make it valid.
	// This field is to be used by the token drivers to list any additional identities that must
	// sign the token request.
	ExtraSigners []view.Identity
}

Issue contains information about an issue operation. In particular, it carries the identities of the issuer and the receivers

type IssueAction

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

IssueAction represents an action that issues tokens.

func (*IssueAction) GetIssuer

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

GetIssuer returns the issuer of the action.

func (*IssueAction) GetMetadata

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

GetMetadata returns the metadata of the action.

func (*IssueAction) GetSerializedOutputs

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

GetSerializedOutputs returns the serialized outputs of the action.

func (*IssueAction) IsAnonymous

func (i *IssueAction) IsAnonymous() bool

IsAnonymous returns true if the action is an anonymous action.

func (*IssueAction) NumOutputs

func (i *IssueAction) NumOutputs() int

NumOutputs returns the number of outputs in the action.

func (*IssueAction) Serialize

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

Serialize returns the byte representation of the action.

type IssueMetadata

type IssueMetadata struct {
	*driver.IssueMetadata
}

IssueMetadata contains the metadata of an issue action

func (*IssueMetadata) IsOutputAbsent

func (m *IssueMetadata) IsOutputAbsent(j int) bool

IsOutputAbsent returns true if the given output's metadata is absent

func (*IssueMetadata) Match

func (m *IssueMetadata) Match(action *IssueAction) error

Match returns true if the given action matches this metadata

type IssueOption

type IssueOption func(*IssueOptions) error

IssueOption is a function that modify IssueOptions

func WithIssueAttribute

func WithIssueAttribute(attr, value interface{}) IssueOption

WithIssueAttribute sets an attribute to be used to customize the issue command

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 IssuerWallet

type IssuerWallet struct {
	*Wallet
	// contains filtered or unexported fields
}

IssuerWallet models the wallet of an issuer

func (*IssuerWallet) GetIssuerIdentity

func (i *IssuerWallet) GetIssuerIdentity(tokenType string) (view.Identity, error)

GetIssuerIdentity returns the issuer identity. This can be a long term identity or a pseudonym depending on the underlying token driver.

func (*IssuerWallet) GetSigner

func (i *IssuerWallet) GetSigner(identity view.Identity) (Signer, error)

GetSigner returns the signer bound to the passed issuer identity.

func (*IssuerWallet) ListIssuedTokens

func (i *IssuerWallet) ListIssuedTokens(opts ...ListTokensOption) (*token.IssuedTokens, error)

ListIssuedTokens returns the list of tokens issued by identities in this wallet and filter by the passed options. Options: WithType

type Ledger

type Ledger interface {
	GetState(key string) ([]byte, error)
}

Ledger models a read-only ledger

type ListTokensOption

type ListTokensOption func(*ListTokensOptions) error

ListTokensOption is a function that configures a ListTokensOptions

func WithType

func WithType(tokenType string) ListTokensOption

WithType returns a list token option that filter by the passed token type. If the passed token type is the empty string, all token types are selected.

type ListTokensOptions

type ListTokensOptions struct {
	TokenType string
}

ListTokensOptions options for listing tokens

type ManagementService

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

ManagementService (TMS, for short) is the entry point for the Token API. A TMS is uniquely identified by a network, channel, namespace, and public parameters. The TMS gives access, among other things, to the wallet manager, the public parameters, the token selector, and so on.

func GetManagementService

func GetManagementService(sp ServiceProvider, opts ...ServiceOption) *ManagementService

GetManagementService returns the management service for the passed options. If no options are passed, the default management service is returned. Options: WithNetwork, WithChannel, WithNamespace, WithPublicParameterFetcher, WithTMS, WithTMSID The function panics if an error occurs. Use GetManagementServiceProvider(sp).GetManagementService(opts...) to handle any error directly

func (*ManagementService) CertificationClient

func (t *ManagementService) CertificationClient() (*CertificationClient, error)

CertificationClient returns the certification client for this TMS

func (*ManagementService) CertificationManager

func (t *ManagementService) CertificationManager() *CertificationManager

CertificationManager returns the certification manager for this TMS

func (*ManagementService) Channel

func (t *ManagementService) Channel() string

Channel returns the channel identifier

func (*ManagementService) ConfigManager

func (t *ManagementService) ConfigManager() *ConfigManager

ConfigManager returns the configuration manager for this TMS

func (*ManagementService) ID

func (t *ManagementService) ID() TMSID

ID returns the TMS identifier

func (*ManagementService) Namespace

func (t *ManagementService) Namespace() string

Namespace returns the namespace identifier, empty if not defined

func (*ManagementService) Network

func (t *ManagementService) Network() string

Network returns the network identifier

func (*ManagementService) NewMetadataFromBytes

func (t *ManagementService) NewMetadataFromBytes(raw []byte) (*Metadata, error)

NewMetadataFromBytes unmarshals the passed bytes into a Metadata object

func (*ManagementService) NewRequest

func (t *ManagementService) NewRequest(id string) (*Request, error)

NewRequest returns a new Token Request whose anchor is the passed id

func (*ManagementService) NewRequestFromBytes

func (t *ManagementService) NewRequestFromBytes(anchor string, actions []byte, meta []byte) (*Request, error)

NewRequestFromBytes returns a new Token Request for the passed anchor, and whose actions and metadata are unmarshalled from the passed bytes

func (*ManagementService) PublicParametersManager

func (t *ManagementService) PublicParametersManager() *PublicParametersManager

PublicParametersManager returns a manager that gives access to the public parameters governing this TMS.

func (*ManagementService) SelectorManager

func (t *ManagementService) SelectorManager() SelectorManager

SelectorManager returns a manager that gives access to the token selectors

func (*ManagementService) SigService

func (t *ManagementService) SigService() *SignatureService

SigService returns the signature service for this TMS

func (*ManagementService) String

func (t *ManagementService) String() string

String returns a string representation of the TMS

func (*ManagementService) Validator

func (t *ManagementService) Validator() (*Validator, error)

Validator returns a new token validator for this TMS

func (*ManagementService) Vault

func (t *ManagementService) Vault() *Vault

Vault returns the Token Vault for this TMS

func (*ManagementService) WalletManager

func (t *ManagementService) WalletManager() *WalletManager

WalletManager returns the wallet manager for this TMS

type ManagementServiceProvider

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

ManagementServiceProvider provides instances of the management service

func GetManagementServiceProvider

func GetManagementServiceProvider(sp ServiceProvider) *ManagementServiceProvider

GetManagementServiceProvider returns the management service provider from the passed service provider. The function panics if an error occurs. An alternative way is to use `s, err := sp.GetService(&ManagementServiceProvider{}) and catch the error manually.`

func NewManagementServiceProvider

func NewManagementServiceProvider(
	sp ServiceProvider,
	tmsProvider driver.TokenManagerServiceProvider,
	normalizer Normalizer,
	vaultProvider VaultProvider,
	certificationClientProvider CertificationClientProvider,
	selectorManagerProvider SelectorManagerProvider,
) *ManagementServiceProvider

NewManagementServiceProvider returns a new instance of ManagementServiceProvider

func (*ManagementServiceProvider) GetManagementService

func (p *ManagementServiceProvider) GetManagementService(opts ...ServiceOption) (*ManagementService, error)

GetManagementService returns an instance of the management service for the passed options. If the management service has not been created yet, it will be created.

type Metadata

type Metadata struct {
	TMS                  TMS
	TokenRequestMetadata *driver.TokenRequestMetadata
}

Metadata contains the metadata of a Token Request

func (*Metadata) FilterBy

func (m *Metadata) FilterBy(eIDs ...string) (*Metadata, error)

FilterBy returns a new Metadata containing only the metadata that matches the given enrollment IDs. For Issue actions, for each issue: - The sender; - The returned metadata will contain only the outputs whose owner has the given enrollment IDs. For Transfer actions, for each action: - The list of token IDs will be empty; - The returned metadata will contain only the outputs whose owner has the given enrollment IDs; - The senders are included if and only if there is at least one output whose owner has the given enrollment IDs. Application metadata is always included

func (*Metadata) GetToken

func (m *Metadata) GetToken(raw []byte) (*token.Token, view.Identity, []byte, error)

GetToken unmarshals the given bytes to extract the token and its issuer (if any).

func (*Metadata) Issue

func (m *Metadata) Issue(i int) (*IssueMetadata, error)

Issue returns the i-th issue metadata, if present

func (*Metadata) SpentTokenID

func (m *Metadata) SpentTokenID() []*token.ID

SpentTokenID returns the token IDs of the tokens that were spent by the Token Request this metadata is associated with.

func (*Metadata) Transfer

func (m *Metadata) Transfer(i int) (*TransferMetadata, error)

Transfer returns the i-th transfer metadata, if present

type Normalizer

type Normalizer interface {
	// Normalize normalizes the given ServiceOptions struct.
	Normalize(opt *ServiceOptions) (*ServiceOptions, error)
}

Normalizer is used to set default values of ServiceOptions struct, if needed.

type Output

type Output struct {
	// ActionIndex is the index of the action that created this output
	ActionIndex int
	// Index is the absolute position of this output in the token request
	Index uint64
	// Owner is the identity of the owner of this output
	Owner view.Identity
	// OwnerAuditInfo contains the audit information of the output's owner
	OwnerAuditInfo []byte
	// EnrollmentID is the enrollment ID of the owner of this output
	EnrollmentID string
	// RevocationHandler is the revocation handler of the owner of this output
	RevocationHandler string
	// Type is the type of token
	Type string
	// Quantity is the quantity of tokens
	Quantity token2.Quantity
}

Output models the output of a token action

func (Output) ID

func (o Output) ID(txID string) *token2.ID

type OutputStream

type OutputStream struct {
	Precision uint64
	// contains filtered or unexported fields
}

OutputStream models a stream over a set of outputs (Output).

func NewOutputStream

func NewOutputStream(outputs []*Output, precision uint64) *OutputStream

NewOutputStream creates a new OutputStream for the passed outputs and Precision.

func (*OutputStream) At

func (o *OutputStream) At(i int) *Output

At returns the output at the passed index.

func (*OutputStream) ByEnrollmentID

func (o *OutputStream) ByEnrollmentID(id string) *OutputStream

ByEnrollmentID filters to only include outputs that match the passed enrollment ID.

func (*OutputStream) ByRecipient

func (o *OutputStream) ByRecipient(id view.Identity) *OutputStream

ByRecipient filters the OutputStream to only include outputs that match the passed recipient.

func (*OutputStream) ByType

func (o *OutputStream) ByType(typ string) *OutputStream

ByType filters the OutputStream to only include outputs that match the passed type.

func (*OutputStream) Count

func (o *OutputStream) Count() int

Count returns the number of outputs in the OutputStream.

func (*OutputStream) EnrollmentIDs

func (o *OutputStream) EnrollmentIDs() []string

EnrollmentIDs returns the enrollment IDs of the outputs in the OutputStream.

func (*OutputStream) Filter

func (o *OutputStream) Filter(f func(t *Output) bool) *OutputStream

Filter filters the OutputStream to only include outputs that match the passed predicate.

func (*OutputStream) Outputs

func (o *OutputStream) Outputs() []*Output

Outputs returns the outputs of the OutputStream.

func (*OutputStream) RevocationHandlers added in v0.3.0

func (o *OutputStream) RevocationHandlers() []string

RevocationHandlers returns the Revocation Handlers of the outputs in the OutputStream.

func (*OutputStream) RevocationHandles added in v0.3.0

func (is *OutputStream) RevocationHandles() []string

RevocationHandles returns the Revocation Handles of the owners of the outputs. It might be empty, if not available.

func (*OutputStream) Sum

func (o *OutputStream) Sum() *big.Int

Sum returns the sum of the quantity of all outputs in the OutputStream.

func (*OutputStream) TokenTypes

func (o *OutputStream) TokenTypes() []string

TokenTypes returns the token types of the outputs in the OutputStream.

type OwnerFilter

type OwnerFilter interface {
	// ID is the wallet identifier of the owner
	ID() string
	// ContainsToken returns true if the passed token is recognized, false otherwise.
	ContainsToken(token *token2.UnspentToken) bool
}

OwnerFilter tells if a passed identity is recognized

type OwnerStream

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

func NewOwnerStream

func NewOwnerStream(owners []string) *OwnerStream

func (*OwnerStream) Count

func (s *OwnerStream) Count() int

type OwnerWallet

type OwnerWallet struct {
	*Wallet
	// contains filtered or unexported fields
}

OwnerWallet models the wallet of an owner

func (*OwnerWallet) EnrollmentID

func (o *OwnerWallet) EnrollmentID() string

func (*OwnerWallet) GetAuditInfo

func (o *OwnerWallet) GetAuditInfo(id view.Identity) ([]byte, error)

GetAuditInfo returns the audit info bound to the passed owner identity.

func (*OwnerWallet) GetRecipientIdentity

func (o *OwnerWallet) GetRecipientIdentity() (view.Identity, error)

GetRecipientIdentity returns the owner identity. This can be a long term identity or a pseudonym depending on the underlying token driver.

func (*OwnerWallet) GetSigner

func (o *OwnerWallet) GetSigner(identity view.Identity) (driver.Signer, error)

GetSigner returns the signer bound to the passed owner identity.

func (*OwnerWallet) GetTokenMetadata

func (o *OwnerWallet) GetTokenMetadata(token []byte) ([]byte, error)

GetTokenMetadata returns the token metadata bound to the passed owner identity.

func (*OwnerWallet) ListUnspentTokens

func (o *OwnerWallet) ListUnspentTokens(opts ...ListTokensOption) (*token.UnspentTokens, error)

ListUnspentTokens returns a list of unspent tokens owned by identities in this wallet and filtered by the passed options. Options: WithType

func (*OwnerWallet) ListUnspentTokensIterator

func (o *OwnerWallet) ListUnspentTokensIterator(opts ...ListTokensOption) (*UnspentTokensIterator, error)

ListUnspentTokensIterator returns an iterator of unspent tokens owned by identities in this wallet and filtered by the passed options. Options: WithType

func (*OwnerWallet) RegisterRecipient added in v0.3.0

func (o *OwnerWallet) RegisterRecipient(identity view.Identity, auditInfo []byte, metadata []byte) error

type PublicParameters added in v0.3.0

type PublicParameters struct {
	driver.PublicParameters
	// contains filtered or unexported fields
}

func (*PublicParameters) Auditors added in v0.3.0

func (c *PublicParameters) Auditors() []view.Identity

Auditors returns the list of auditors' identities

func (*PublicParameters) CertificationDriver added in v0.3.0

func (c *PublicParameters) CertificationDriver() string

CertificationDriver return the certification driver used to certify that tokens exist

func (*PublicParameters) GraphHiding added in v0.3.0

func (c *PublicParameters) GraphHiding() bool

GraphHiding returns true if graph hiding is enabled

func (*PublicParameters) Identifier added in v0.3.0

func (c *PublicParameters) Identifier() string

Identifier returns the identifier of the public parameters

func (*PublicParameters) MaxTokenValue added in v0.3.0

func (c *PublicParameters) MaxTokenValue() uint64

MaxTokenValue returns the maximum value a token can contain

func (*PublicParameters) Precision added in v0.3.0

func (c *PublicParameters) Precision() uint64

Precision returns the precision used to represent the token quantity

func (*PublicParameters) Serialize added in v0.3.0

func (c *PublicParameters) Serialize() ([]byte, error)

Serialize returns the public parameters in their serialized form

func (*PublicParameters) TokenDataHiding added in v0.3.0

func (c *PublicParameters) TokenDataHiding() bool

TokenDataHiding returns true if data hiding is enabled

type PublicParametersManager

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

PublicParametersManager exposes methods to manage the public parameters

func NewPublicParametersManagerFromPublicParams

func NewPublicParametersManagerFromPublicParams(params []byte) (*PublicParametersManager, error)

func (*PublicParametersManager) Fetch

func (c *PublicParametersManager) Fetch() ([]byte, error)

Fetch fetches the public parameters from the backend

func (*PublicParametersManager) PublicParameters added in v0.3.0

func (c *PublicParametersManager) PublicParameters() *PublicParameters

PublicParameters returns the public parameters, nil if not set yet.

func (*PublicParametersManager) SetPublicParameters added in v0.2.0

func (c *PublicParametersManager) SetPublicParameters(raw []byte) error

SetPublicParameters updates the public parameters with the passed value

func (*PublicParametersManager) Validate

func (c *PublicParametersManager) Validate() error

Validate validates the public parameters

type PublicParamsFetcher

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

PublicParamsFetcher models the public parameters fetcher

type QueryEngine

type QueryEngine struct {

	// Variables used to control retry condition
	NumRetries int
	RetryDelay time.Duration
	// contains filtered or unexported fields
}

QueryEngine models a token query engine

func NewQueryEngine added in v0.3.0

func NewQueryEngine(qe driver.QueryEngine, numRetries int, retryDelay time.Duration) *QueryEngine

func (*QueryEngine) GetTokens

func (q *QueryEngine) GetTokens(inputs ...*token2.ID) ([]*token2.Token, error)

GetTokens returns the tokens stored in the vault matching the given ids

func (*QueryEngine) IsMine

func (q *QueryEngine) IsMine(id *token2.ID) (bool, error)

IsMine returns true is the given token is in this vault and therefore owned by this client

func (*QueryEngine) ListAuditTokens

func (q *QueryEngine) ListAuditTokens(ids ...*token2.ID) ([]*token2.Token, error)

func (*QueryEngine) ListHistoryIssuedTokens

func (q *QueryEngine) ListHistoryIssuedTokens() (*token2.IssuedTokens, error)

func (*QueryEngine) ListUnspentTokens

func (q *QueryEngine) ListUnspentTokens() (*token2.UnspentTokens, error)

ListUnspentTokens returns a list of all unspent tokens stored in the vault

func (*QueryEngine) PublicParams

func (q *QueryEngine) PublicParams() ([]byte, error)

PublicParams returns the public parameters stored in the vault

func (*QueryEngine) UnspentTokensIterator

func (q *QueryEngine) UnspentTokensIterator() (*UnspentTokensIterator, error)

UnspentTokensIterator returns an iterator over all unspent tokens stored in the vault

func (*QueryEngine) UnspentTokensIteratorBy

func (q *QueryEngine) UnspentTokensIteratorBy(walletID, tokenType string) (*UnspentTokensIterator, error)

UnspentTokensIteratorBy is an iterator over all unspent tokens in this vault owned by passed wallet id and whose token type matches the passed token type

type QueryService

type QueryService interface {
	IsMine(id *token2.ID) (bool, error)
}

type RecipientData added in v0.3.0

type RecipientData struct {
	Identity  view.Identity
	AuditInfo []byte
	Metadata  []byte
}

type Request

type Request struct {
	// Anchor is used to bind the Actions to a given Transaction
	Anchor string
	// Actions contains the token operations.
	Actions *driver.TokenRequest
	// Metadata contains the actions' metadata used to unscramble the content of the actions, if the
	// underlying token driver requires that
	Metadata *driver.TokenRequestMetadata
	// TokenService this request refers to
	TokenService *ManagementService `json:"-"`
}

Request aggregates token operations that must be performed atomically. Operations are represented in a backend agnostic way but driver specific.

func NewRequest

func NewRequest(tokenService *ManagementService, anchor string) *Request

NewRequest creates a new empty request for the given token service and anchor

func NewRequestFromBytes

func NewRequestFromBytes(tokenService *ManagementService, anchor string, actions []byte, trmRaw []byte) (*Request, error)

NewRequestFromBytes creates a new request from the given anchor, and whose actions and metadata are unmarshalled from the given bytes

func (*Request) AddAuditorSignature

func (r *Request) AddAuditorSignature(sigma []byte)

AddAuditorSignature adds an auditor signature to the request.

func (*Request) ApplicationMetadata

func (r *Request) ApplicationMetadata(k string) []byte

ApplicationMetadata returns the application metadata corresponding to the given key

func (*Request) AuditCheck

func (r *Request) AuditCheck() error

AuditCheck performs the audit check of the request in addition to the checks of the token request itself via IsValid.

func (*Request) AuditRecord

func (r *Request) AuditRecord() (*AuditRecord, error)

AuditRecord return the audit record of the request. The audit record contains: The anchor, the audit inputs and outputs

func (*Request) BindTo

func (r *Request) BindTo(sp view2.ServiceProvider, party view.Identity) error

BindTo binds transfers' senders and receivers, that are senders, that are not me to the passed identity

func (*Request) Bytes

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

Bytes marshals the request to bytes. It includes: Anchor (or ID), actions, and metadata.

func (*Request) FilterMetadataBy

func (r *Request) FilterMetadataBy(eIDs ...string) (*Request, error)

FilterMetadataBy returns a new Request with the metadata filtered by the given enrollment IDs.

func (*Request) FromBytes

func (r *Request) FromBytes(request []byte) error

FromBytes unmarshalls the request from bytes overriding the content of the current request.

func (*Request) GetMetadata

func (r *Request) GetMetadata() (*Metadata, error)

GetMetadata returns the metadata of the request.

func (*Request) ID

func (r *Request) ID() string

ID returns the anchor of the request

func (*Request) Inputs

func (r *Request) Inputs() (*InputStream, error)

Inputs returns the sequence of inputs of the request supporting sequential and parallel aggregate operations. Notice that the inputs do not carry Type and Quantity because this information might be available to all parties. If you are an auditor, you can use the AuditInputs method to get everything.

func (*Request) InputsAndOutputs added in v0.3.0

func (r *Request) InputsAndOutputs() (*InputStream, *OutputStream, error)

func (*Request) IsValid

func (r *Request) IsValid() error

IsValid checks that the request is valid.

func (*Request) Issue

func (r *Request) Issue(wallet *IssuerWallet, receiver view.Identity, typ string, q uint64, opts ...IssueOption) (*IssueAction, error)

Issue appends an issue action to the request. The action will be prepared using the provided issuer wallet. The action issues to the receiver a token of the passed type and quantity. Additional options can be passed to customize the action.

func (*Request) IssueSigners added in v0.3.0

func (r *Request) IssueSigners() []view.Identity

func (*Request) Issues

func (r *Request) Issues() []*Issue

Issues returns the list of issued tokens.

func (*Request) MarshalToAudit

func (r *Request) MarshalToAudit() ([]byte, error)

MarshalToAudit marshals the request to a message suitable for audit signature. In particular, metadata is not included.

func (*Request) MarshalToSign

func (r *Request) MarshalToSign() ([]byte, error)

MarshalToSign marshals the request to a message suitable for signing.

func (*Request) MetadataToBytes

func (r *Request) MetadataToBytes() ([]byte, error)

MetadataToBytes marshals the request's metadata to bytes.

func (*Request) Outputs

func (r *Request) Outputs() (*OutputStream, error)

Outputs returns the sequence of outputs of the request supporting sequential and parallel aggregate operations.

func (*Request) PutSignatures added in v0.3.0

func (r *Request) PutSignatures(sigmas map[string][]byte)

func (*Request) Redeem

func (r *Request) Redeem(wallet *OwnerWallet, typ string, value uint64, opts ...TransferOption) error

Redeem appends a redeem action to the request. The action will be prepared using the provided owner wallet. The action redeems tokens of the passed type for a total amount matching the passed value. Additional options can be passed to customize the action.

func (*Request) RequestToBytes

func (r *Request) RequestToBytes() ([]byte, error)

RequestToBytes marshals the request's actions to bytes.

func (*Request) SetApplicationMetadata

func (r *Request) SetApplicationMetadata(k string, v []byte)

SetApplicationMetadata sets application metadata in terms of key-value pairs. The Token-SDK does not control the format of the metadata.

func (*Request) SetTokenService

func (r *Request) SetTokenService(service *ManagementService)

SetTokenService sets the token service.

func (*Request) Transfer

func (r *Request) Transfer(wallet *OwnerWallet, typ string, values []uint64, owners []view.Identity, opts ...TransferOption) (*TransferAction, error)

Transfer appends a transfer action to the request. The action will be prepared using the provided owner wallet. The action transfers tokens of the passed types to the receivers for the passed quantities. In other words, owners[0] will receives values[0], and so on. Additional options can be passed to customize the action.

func (*Request) TransferSigners added in v0.3.0

func (r *Request) TransferSigners() []view.Identity

func (*Request) Transfers

func (r *Request) Transfers() []*Transfer

Transfers returns the list of transfers.

type Selector

type Selector interface {
	// Select returns the list of token identifiers where
	// 1. The owner match the passed owner filter.
	// 2. The type is equal to the passed token type.
	// 3. The sum of amount in each token is at least the passed quantity.
	// Quantity is a string in decimal format
	// Notice that, the quantity selected might exceed the quantity requested due to the amounts
	// stored in each token.
	Select(ownerFilter OwnerFilter, q, tokenType string) ([]*token2.ID, token2.Quantity, error)
}

Selector is the interface of token selectors

type SelectorManager

type SelectorManager interface {
	// NewSelector returns a new Selector instance bound the passed id.
	NewSelector(id string) (Selector, error)
	// Unlock unlocks the tokens bound to the passed id, if any
	Unlock(id string) error
}

SelectorManager handles token selection operations

type SelectorManagerProvider

type SelectorManagerProvider interface {
	// SelectorManager returns a SelectorManager instance for the passed inputs.
	SelectorManager(network string, channel string, namespace string) SelectorManager
}

SelectorManagerProvider provides instances of SelectorManager

type ServiceOption

type ServiceOption func(*ServiceOptions) error

ServiceOption is a function that configures a ServiceOptions

func WithChannel

func WithChannel(channel string) ServiceOption

WithChannel sets the channel

func WithNamespace

func WithNamespace(namespace string) ServiceOption

WithNamespace sets the namespace for the service

func WithNetwork

func WithNetwork(network string) ServiceOption

WithNetwork sets the network name

func WithPublicParameterFetcher

func WithPublicParameterFetcher(ppFetcher PublicParamsFetcher) ServiceOption

WithPublicParameterFetcher sets the public parameter fetcher

func WithTMS

func WithTMS(network, channel, namespace string) ServiceOption

WithTMS filters by network, channel and namespace. Each of them can be empty

func WithTMSID

func WithTMSID(id TMSID) ServiceOption

WithTMSID filters by TMS identifier

type ServiceOptions

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
	// Params is used to store any application specific parameter
	Params map[string]interface{}
}

ServiceOptions is used to configure the service

func CompileServiceOptions

func CompileServiceOptions(opts ...ServiceOption) (*ServiceOptions, error)

CompileServiceOptions compiles the given list of ServiceOption

func (ServiceOptions) ParamAsString

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) TMSID

func (o ServiceOptions) TMSID() TMSID

TMSID returns the TMSID for the given ServiceOptions

type ServiceProvider

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 SignatureService

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

SignatureService gives access to signature verifiers and signers bound to identities known by this service

func (*SignatureService) AuditorVerifier

func (s *SignatureService) AuditorVerifier(id view.Identity) (Verifier, error)

AuditorVerifier returns a signature verifier for the given auditor identity

func (*SignatureService) GetSigner

func (s *SignatureService) GetSigner(id view.Identity) (Signer, error)

GetSigner returns a signer bound to the given identity

func (*SignatureService) IsMe

func (s *SignatureService) IsMe(party view.Identity) bool

IsMe returns true if for the given identity there is a signer registered

func (*SignatureService) IssuerVerifier

func (s *SignatureService) IssuerVerifier(id view.Identity) (Verifier, error)

IssuerVerifier returns a signature verifier for the given issuer identity

func (*SignatureService) OwnerVerifier

func (s *SignatureService) OwnerVerifier(id view.Identity) (Verifier, error)

OwnerVerifier returns a signature verifier for the given owner identity

func (*SignatureService) RegisterSigner

func (s *SignatureService) RegisterSigner(identity view.Identity, signer Signer, verifier Verifier) error

RegisterSigner registers the pair (signer, verifier) bound to the given identity

type Signer

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

Signer models a signature signer

type TMS

type TMS interface {
	// DeserializeToken returns the token and its issuer (if any).
	DeserializeToken(outputRaw []byte, tokenInfoRaw []byte) (*token.Token, view.Identity, error)
	// GetTokenInfo extracts from the given metadata the token info entry corresponding to the given target
	GetTokenInfo(meta *driver.TokenRequestMetadata, target []byte) ([]byte, error)
	// GetEnrollmentID extracts the enrollment id from the passed audit information
	GetEnrollmentID(bytes []byte) (string, error)
}

type TMSID

type TMSID struct {
	Network   string
	Channel   string
	Namespace string
}

TMSID models a TMS identifier

func (TMSID) String

func (t TMSID) String() string

String returns a string representation of the TMSID

type Transfer

type Transfer struct {
	// Senders is the list of identities of the senders
	Senders []view.Identity
	// Receivers is the list of identities of the receivers
	Receivers []view.Identity
	// ExtraSigners is the list of extra identities that must sign the token request to make it valid.
	// This field is to be used by the token drivers to list any additional identities that must
	// sign the token request.
	ExtraSigners []view.Identity
}

Transfer contains information about a transfer operation. In particular, it carries the identities of the senders and the receivers

type TransferAction

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

TransferAction represents an action that transfers tokens.

func (*TransferAction) GetInputs

func (t *TransferAction) GetInputs() ([]string, error)

GetInputs returns the input ids used in the action.

func (*TransferAction) GetSerializedOutputs

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

GetSerializedOutputs returns the serialized outputs of the action.

func (*TransferAction) IsGraphHiding

func (t *TransferAction) IsGraphHiding() bool

IsGraphHiding returns true if the action supports graph hiding.

func (*TransferAction) IsRedeemAt

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

IsRedeemAt returns true if the i-th output redeems.

func (*TransferAction) NumOutputs

func (t *TransferAction) NumOutputs() int

NumOutputs returns the number of outputs in the action.

func (*TransferAction) Serialize

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

Serialize returns the byte representation of the action.

func (*TransferAction) SerializeOutputAt

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

SerializeOutputAt returns the serialized output at the i-th position.

type TransferMetadata

type TransferMetadata struct {
	*driver.TransferMetadata
}

TransferMetadata contains the metadata of a transfer action

func (*TransferMetadata) IsInputAbsent

func (m *TransferMetadata) IsInputAbsent(j int) bool

IsInputAbsent returns true if the given input's metadata is absent

func (*TransferMetadata) IsOutputAbsent

func (m *TransferMetadata) IsOutputAbsent(j int) bool

IsOutputAbsent returns true if the given output's metadata is absent

func (*TransferMetadata) Match

func (m *TransferMetadata) Match(action *TransferAction) error

Match returns true if the given action matches this metadata

type TransferOption

type TransferOption func(*TransferOptions) error

TransferOption is a function that modify TransferOptions

func WithRestRecipientIdentity added in v0.3.0

func WithRestRecipientIdentity(recipientData *RecipientData) TransferOption

WithRestRecipientIdentity sets the recipient data to be used to assign any rest left during a transfer operation

func WithTokenIDs

func WithTokenIDs(ids ...*token.ID) TransferOption

WithTokenIDs sets the tokens ids to transfer

func WithTokenSelector

func WithTokenSelector(selector Selector) TransferOption

WithTokenSelector sets the passed token selector

func WithTransferAttribute

func WithTransferAttribute(attr, value interface{}) TransferOption

WithTransferAttribute sets an attribute to be used to customize the transfer command

func WithTransferMetadata

func WithTransferMetadata(key string, value []byte) TransferOption

WithTransferMetadata sets transfer action metadata

type TransferOptions

type TransferOptions struct {
	// Attributes is a container of generic options that might be driver specific
	Attributes map[interface{}]interface{}
	// Selector is the custom token selector to use. If nil, the default will be used.
	Selector Selector
	// TokenIDs to transfer. If empty, the tokens will be selected.
	TokenIDs []*token.ID
	// RestRecipientIdentity TODO:
	RestRecipientIdentity *RecipientData
}

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

type UnspentTokensIterator

type UnspentTokensIterator struct {
	driver.UnspentTokensIterator
}

UnspentTokensIterator models an iterator over all unspent tokens stored in the vault

func (*UnspentTokensIterator) Sum

func (u *UnspentTokensIterator) Sum(precision uint64) (token2.Quantity, error)

Sum computes the sum of the quantities of the tokens in the iterator. Sum closes the iterator at the end of the execution.

type Validator

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

Validator validates a token request

func (*Validator) UnmarshalActions

func (c *Validator) UnmarshalActions(raw []byte) ([]interface{}, error)

UnmarshalActions returns the actions contained in the serialized token request

func (*Validator) UnmarshallAndVerify

func (c *Validator) UnmarshallAndVerify(ledger Ledger, anchor string, raw []byte) ([]interface{}, error)

UnmarshallAndVerify unmarshalls the token request and verifies it against the passed ledger and anchor

func (*Validator) UnmarshallAndVerifyWithMetadata added in v0.3.0

func (c *Validator) UnmarshallAndVerifyWithMetadata(ledger Ledger, anchor string, raw []byte) ([]interface{}, map[string][]byte, error)

UnmarshallAndVerifyWithMetadata behaves as UnmarshallAndVerify. In addition, it returns the metadata extracts from the token request in the form of map.

type Vault

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

Vault models a token vault

func (*Vault) NewQueryEngine

func (v *Vault) NewQueryEngine() *QueryEngine

NewQueryEngine returns a new query engine

type VaultProvider

type VaultProvider interface {
	// Vault returns a token vault instance for the passed inputs
	Vault(network string, channel string, namespace string) (driver.Vault, error)
}

VaultProvider provides token vault instances

type Verifier

type Verifier interface {
	// Verify verifies the signature of a given message
	Verify(message, sigma []byte) error
}

Verifier models a signature verifier

type Wallet

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

Wallet models a generic wallet that has an identifier and contains one or mode identities. These identities own tokens.

func (*Wallet) Contains

func (w *Wallet) Contains(identity view.Identity) bool

Contains returns true if the wallet contains the passed identity.

func (*Wallet) ContainsToken

func (w *Wallet) ContainsToken(token *token.UnspentToken) bool

ContainsToken returns true if the wallet contains an identity that owns the passed token.

func (*Wallet) ID

func (w *Wallet) ID() string

ID returns the wallet identifier.

func (*Wallet) TMS

func (w *Wallet) TMS() *ManagementService

TMS returns the token management service.

type WalletManager

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

WalletManager defines the interface for managing wallets.

func NewWalletManager added in v0.3.0

func NewWalletManager(sp view.ServiceProvider, network string, channel string, namespace string, params []byte) (*WalletManager, error)

func (*WalletManager) AuditorWallet

func (wm *WalletManager) AuditorWallet(id string) *AuditorWallet

AuditorWallet returns the auditor wallet bound to the passed identifier, if any is available. The identifier can be a label, as defined in the configuration file, an identity or a wallet ID. If no wallet is found, it returns nil.

func (*WalletManager) AuditorWalletByIdentity

func (wm *WalletManager) AuditorWalletByIdentity(id view.Identity) *AuditorWallet

func (*WalletManager) CertifierWallet

func (wm *WalletManager) CertifierWallet(id string) *CertifierWallet

CertifierWallet returns the certifier wallet bound to the passed identifier, if any is available. The identifier can be a label, as defined in the configuration file, an identity or a wallet ID. If no wallet is found, it returns nil.

func (*WalletManager) CertifierWalletByIdentity

func (wm *WalletManager) CertifierWalletByIdentity(identity view.Identity) *CertifierWallet

CertifierWalletByIdentity returns the certifier wallet bound to the passed identity, if any is available. If no wallet is found, it returns nil.

func (*WalletManager) GetEnrollmentID

func (wm *WalletManager) GetEnrollmentID(identity view.Identity) (string, error)

GetEnrollmentID returns the enrollment ID of passed identity

func (*WalletManager) GetRevocationHandle added in v0.3.0

func (wm *WalletManager) GetRevocationHandle(identity view.Identity) (string, error)

GetRevocationHandle returns the revocation handle of the passed identity

func (*WalletManager) IsMe

func (wm *WalletManager) IsMe(id view.Identity) bool

func (*WalletManager) IssuerWallet

func (wm *WalletManager) IssuerWallet(id string) *IssuerWallet

IssuerWallet returns the issuer wallet bound to the passed identifier, if any is available. The identifier can be a label, as defined in the configuration file, an identity or a wallet ID. If no wallet is found, it returns nil.

func (*WalletManager) IssuerWalletByIdentity

func (wm *WalletManager) IssuerWalletByIdentity(identity view.Identity) *IssuerWallet

IssuerWalletByIdentity returns the issuer wallet bound to the passed identity, if any is available. If no wallet is found, it returns nil.

func (*WalletManager) OwnerWallet

func (wm *WalletManager) OwnerWallet(id string) *OwnerWallet

OwnerWallet returns the owner wallet bound to the passed identifier, if any is available. The identifier can be a label, as defined in the configuration file, an identity or a wallet ID. If no wallet is found, it returns nil.

func (*WalletManager) OwnerWalletByIdentity

func (wm *WalletManager) OwnerWalletByIdentity(identity view.Identity) *OwnerWallet

OwnerWalletByIdentity returns the owner wallet bound to the passed identity, if any is available. If no wallet is found, it returns nil.

func (*WalletManager) OwnerWalletIDs added in v0.3.0

func (wm *WalletManager) OwnerWalletIDs() ([]string, error)

OwnerWalletIDs returns the list of owner wallet identifiers

func (*WalletManager) RegisterIssuerWallet

func (wm *WalletManager) RegisterIssuerWallet(id string, path string) error

RegisterIssuerWallet registers a new issuer wallet with the passed id

func (*WalletManager) RegisterOwnerWallet

func (wm *WalletManager) RegisterOwnerWallet(id string, path string) error

RegisterOwnerWallet registers a new owner wallet with the passed id

func (*WalletManager) RegisterRecipientIdentity

func (wm *WalletManager) RegisterRecipientIdentity(id view.Identity, auditInfo []byte, metadata []byte) error

RegisterRecipientIdentity registers a new recipient identity

func (*WalletManager) SpentIDs

func (wm *WalletManager) SpentIDs(ids []*token.ID) ([]string, error)

SpentIDs returns the spent keys corresponding to the passed token IDs

func (*WalletManager) Wallet

func (wm *WalletManager) Wallet(identity view.Identity) *Wallet

Wallet returns the wallet bound to the passed identity, if any is available. If no wallet is found, it returns nil.

Directories

Path Synopsis
zkatdlog/crypto/audit/mock
Code generated by counterfeiter.
Code generated by counterfeiter.
zkatdlog/crypto/issue/nonanonym/mock
Code generated by counterfeiter.
Code generated by counterfeiter.
zkatdlog/crypto/transfer/mock
Code generated by counterfeiter.
Code generated by counterfeiter.
zkatdlog/crypto/validator/mock
Code generated by counterfeiter.
Code generated by counterfeiter.
Code generated by counterfeiter.
Code generated by counterfeiter.
sdk
tms
services
network/fabric/tcc/mock
Code generated by counterfeiter.
Code generated by counterfeiter.
ttx
vault/translator/mock
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