translator

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: 7 Imported by: 2

Documentation

Overview

Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

View Source
var (
	NotEmpty = []byte{1}
)

Functions

This section is empty.

Types

type ActionWithInputs added in v0.5.0

type ActionWithInputs interface {
	// 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
}

type ExRWSet

type ExRWSet interface {
	// SetState adds a write entry to the rwset that write to given value to given key.
	SetState(key Key, value Value) error
	// GetState returns the value bound to the passed key
	GetState(key Key) ([]byte, error)
	// DeleteState adds a write entry to the rwset that deletes the passed key
	DeleteState(key Key) error
	// StateMustNotExist adds a read dependency that enforces that the passed key does not exist
	StateMustNotExist(key Key) error
	// StateMustExist adds a read dependency that enforces that the passed key does exist
	// When using VersionZero, this method should be called only for keys that are guaranteed to be used only once.
	StateMustExist(key Key, version KeyVersion) error
}

ExRWSet interface, used to manipulate the rwset in a more friendly way

type HashedKeyTranslator

type HashedKeyTranslator struct {
	KT KeyTranslator
}

func (*HashedKeyTranslator) CreateInputSNKey

func (h *HashedKeyTranslator) CreateInputSNKey(id string) (Key, error)

func (*HashedKeyTranslator) CreateIssueActionMetadataKey

func (h *HashedKeyTranslator) CreateIssueActionMetadataKey(key Key) (Key, error)

func (*HashedKeyTranslator) CreateOutputKey

func (h *HashedKeyTranslator) CreateOutputKey(id string, index uint64) (Key, error)

func (*HashedKeyTranslator) CreateOutputSNKey

func (h *HashedKeyTranslator) CreateOutputSNKey(id string, index uint64, output []byte) (Key, error)

func (*HashedKeyTranslator) CreateSetupHashKey

func (h *HashedKeyTranslator) CreateSetupHashKey() (Key, error)

func (*HashedKeyTranslator) CreateSetupKey

func (h *HashedKeyTranslator) CreateSetupKey() (Key, error)

func (*HashedKeyTranslator) CreateTokenRequestKey

func (h *HashedKeyTranslator) CreateTokenRequestKey(id string) (Key, error)

func (*HashedKeyTranslator) CreateTransferActionMetadataKey

func (h *HashedKeyTranslator) CreateTransferActionMetadataKey(key Key) (Key, error)

func (*HashedKeyTranslator) GetTransferMetadataSubKey

func (h *HashedKeyTranslator) GetTransferMetadataSubKey(k string) (Key, error)

func (*HashedKeyTranslator) TransferActionMetadataKeyPrefix added in v0.5.0

func (h *HashedKeyTranslator) TransferActionMetadataKeyPrefix() (Key, error)

type IssueAction

type IssueAction interface {
	ActionWithInputs
	Serialize() ([]byte, error)
	NumOutputs() int
	GetSerializedOutputs() ([][]byte, error)
	IsAnonymous() bool
	GetIssuer() []byte
	GetMetadata() map[string][]byte
	// IsGraphHiding returns true if the action is graph hiding
	IsGraphHiding() bool
}

type IssuingValidator

type IssuingValidator interface {
	// Validate returns no error if the passed creator can issue tokens of the passed type,, an error otherwise.
	Validate(creator view.Identity, tokenType string) error
}

IssuingValidator is used to establish if the creator can issue tokens of the passed type.

type Key

type Key = string

type KeyTranslator

type KeyTranslator interface {
	// CreateTokenRequestKey creates the key for a token request with the passed id
	CreateTokenRequestKey(id string) (Key, error)
	// CreateSetupKey creates the key for public parameters
	CreateSetupKey() (Key, error)
	// CreateSetupHashKey creates the key for the hashed public parameters
	CreateSetupHashKey() (Key, error)
	// CreateOutputKey creates the key for an output
	CreateOutputKey(id string, index uint64) (Key, error)
	// CreateOutputSNKey creates the key for the serial number of an output
	CreateOutputSNKey(id string, index uint64, output []byte) (Key, error)
	// CreateInputSNKey creates the key for the serial number of an input
	CreateInputSNKey(id string) (Key, error)
	// CreateIssueActionMetadataKey returns the issue action metadata key built from the passed key
	CreateIssueActionMetadataKey(key string) (Key, error)
	// CreateTransferActionMetadataKey returns the transfer action metadata key built from the passed subkey
	CreateTransferActionMetadataKey(subkey string) (Key, error)
	// GetTransferMetadataSubKey returns the subkey in the given transfer action metadata key
	GetTransferMetadataSubKey(k string) (Key, error)
	// TransferActionMetadataKeyPrefix TODO
	TransferActionMetadataKeyPrefix() (Key, error)
}

KeyTranslator is used to translate tokens' concepts into backend's keys.

type KeyVersion

type KeyVersion = int

KeyVersion models the concept of a specific key version as `version zero` or `any`.

const (
	// Latest value, latest version of the key known to the node
	Latest KeyVersion = iota
	// VersionZero value,  version `zero` of the key
	VersionZero
)

type Namespace

type Namespace = string

type RWSet

type RWSet interface {
	SetState(namespace string, key string, value []byte) error
	GetState(namespace string, key string) ([]byte, error)
	DeleteState(namespace string, key string) error
}

RWSet interface, used to read from, and write to, a rwset.

type RWSetWrapper

type RWSetWrapper struct {
	RWSet     RWSet
	Namespace Namespace
	TxID      TxID
}

func NewRWSetWrapper

func NewRWSetWrapper(RWSet RWSet, namespace Namespace, txID TxID) *RWSetWrapper

func (*RWSetWrapper) DeleteState

func (w *RWSetWrapper) DeleteState(key Key) error

func (*RWSetWrapper) GetState

func (w *RWSetWrapper) GetState(key Key) (Value, error)

func (*RWSetWrapper) SetState

func (w *RWSetWrapper) SetState(key Key, value Value) error

func (*RWSetWrapper) StateMustExist

func (w *RWSetWrapper) StateMustExist(key Key, version KeyVersion) error

func (*RWSetWrapper) StateMustNotExist

func (w *RWSetWrapper) StateMustNotExist(key Key) error

type SetupAction

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

type TransferAction

type TransferAction interface {
	ActionWithInputs
	// 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)
	// 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)
	// 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 Translator

type Translator struct {
	RWSet         ExRWSet
	KeyTranslator KeyTranslator
	TxID          string
	// SpentIDs the spent IDs added so far
	SpentIDs []string
	// contains filtered or unexported fields
}

Translator validates token requests and generates the corresponding RWSets

func New

func New(txID string, rws ExRWSet, keyTranslator KeyTranslator) *Translator

func (*Translator) AddPublicParamsDependency

func (t *Translator) AddPublicParamsDependency() error

func (*Translator) AreTokensSpent

func (t *Translator) AreTokensSpent(ids []string, graphHiding bool) ([]bool, error)

func (*Translator) CommitTokenRequest

func (t *Translator) CommitTokenRequest(raw []byte, storeHash bool) ([]byte, error)

func (*Translator) GetTransferMetadataSubKey

func (t *Translator) GetTransferMetadataSubKey(k string) (string, error)

func (*Translator) QueryTokens

func (t *Translator) QueryTokens(ids []*token.ID) ([][]byte, error)

func (*Translator) ReadSetupParameters

func (t *Translator) ReadSetupParameters() ([]byte, error)

func (*Translator) ReadTokenRequest

func (t *Translator) ReadTokenRequest() ([]byte, error)

func (*Translator) Write

func (t *Translator) Write(action interface{}) error

Write checks that transactions are correct wrt. the most recent rwset state. Write checks are ones that shall be done sequentially, since transactions within a block may introduce dependencies.

type TxID

type TxID = string

type Value

type Value = []byte

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