coin

package
v0.0.0-...-7ece11e Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 14 Imported by: 5

Documentation

Index

Constants

View Source
const (
	MaxSizeInfoCoin   = 255
	JsonMarshalFlag   = 34 //nolint:revive
	CoinVersion1      = 1
	CoinVersion2      = 2
	TxRandomGroupSize = 68
)
View Source
const (
	PedersenPrivateKeyIndex = operation.PedersenPrivateKeyIndex
	PedersenValueIndex      = operation.PedersenValueIndex
	PedersenSndIndex        = operation.PedersenSndIndex
	PedersenShardIDIndex    = operation.PedersenShardIDIndex
	PedersenRandomnessIndex = operation.PedersenRandomnessIndex
)
View Source
const (
	PrivacyTypeTransfer = iota
	PrivacyTypeMint
)
View Source
const MaxAttempts int = 50000

Variables

This section is empty.

Functions

func ComputeAssetTagBlinder

func ComputeAssetTagBlinder(sharedSecret *operation.Point) (*operation.Scalar, error)

func ComputeCommitmentCA

func ComputeCommitmentCA(assetTag *operation.Point, r, v *operation.Scalar) (*operation.Point, error)

func CreatePaymentInfosFromPlainCoinsAndAddress

func CreatePaymentInfosFromPlainCoinsAndAddress(c []PlainCoin, paymentAddress key.PaymentAddress, message []byte) []*key.PaymentInfo

func DeriveShardInfoFromCoin

func DeriveShardInfoFromCoin(coinPubKey []byte) (int, int, int, error)

DeriveShardInfoFromCoin returns the sender origin & receiver shard of a coin based on the PublicKey on that coin (encoded inside its last byte). Does not support MaxShardNumber > 8

func ParseOTAInfoToString

func ParseOTAInfoToString(pubKey *operation.Point, txRandom *TxRandom) (string, string)

Types

type Coin

type Coin interface {
	GetVersion() uint8
	GetCommitment() *operation.Point
	GetInfo() []byte
	GetPublicKey() *operation.Point
	GetKeyImage() *operation.Point
	GetValue() uint64
	GetRandomness() *operation.Scalar
	GetShardID() (uint8, error)
	GetSNDerivator() *operation.Scalar
	GetCoinDetailEncrypted() []byte
	IsEncrypted() bool
	GetTxRandom() *TxRandom
	GetSharedRandom() *operation.Scalar
	GetSharedConcealRandom() *operation.Scalar
	GetAssetTag() *operation.Point
	GetCoinID() [operation.Ed25519KeySize]byte

	// DecryptOutputCoinByKey process outputcoin to get outputcoin data which relate to keyset
	// Param keyset: (private key, payment address, read only key)
	// in case private key: return unspent outputcoin tx
	// in case read only key: return all outputcoin tx with amount value
	// in case payment address: return all outputcoin tx with no amount value
	Decrypt(*incognitokey.KeySet) (PlainCoin, error)

	Bytes() []byte
	SetBytes([]byte) error

	CheckCoinValid(key.PaymentAddress, []byte, uint64) bool
	DoesCoinBelongToKeySet(keySet *incognitokey.KeySet) (bool, *operation.Point)
}

func ArrayCoinV1ToCoin

func ArrayCoinV1ToCoin(inputCoins []*CoinV1) []Coin

func NewCoinFromByte

func NewCoinFromByte(b []byte) (Coin, error)

First byte should determine the version or json marshal "34"

func ParseCoinsFromBytes

func ParseCoinsFromBytes(data []json.RawMessage) ([]Coin, error)

type CoinObject

type CoinObject struct {
	PublicKey      string `json:"PublicKey"`
	CoinCommitment string `json:"CoinCommitment"`
	SNDerivator    string `json:"SNDerivator"`
	SerialNumber   string `json:"SerialNumber"`
	Randomness     string `json:"Randomness"`
	Value          string `json:"Value"`
	Info           string `json:"Info"`
}

type CoinParams

type CoinParams struct {
	key.PaymentInfo
	SenderShardID   int
	CoinPrivacyType int
}

CoinParams contains the necessary data to create a new coin

func (*CoinParams) From

func (p *CoinParams) From(inf *key.PaymentInfo, sid, cptype int) *CoinParams

From initializes the CoinParam using input data (PaymentInfo must not be nil)

func (*CoinParams) FromPaymentInfo

func (p *CoinParams) FromPaymentInfo(inf *key.PaymentInfo) *CoinParams

FromPaymentInfo initializes the CoinParam using a PaymentInfo (must not be nil); others are set to default

type CoinV1

type CoinV1 struct {
	CoinDetails          *PlainCoinV1
	CoinDetailsEncrypted *henc.HybridCipherText
}

OutputCoin represents a output coin of transaction It contains CoinDetails and CoinDetailsEncrypted (encrypted value and randomness) CoinDetailsEncrypted is nil when you send tx without privacy

func ArrayCoinToCoinV1

func ArrayCoinToCoinV1(inputCoins []Coin) []*CoinV1

func (*CoinV1) Bytes

func (c *CoinV1) Bytes() []byte

Bytes (OutputCoin) converts a output coin's details to a bytes array Each fields in coin is saved in len - body format

func (*CoinV1) CheckCoinValid

func (c *CoinV1) CheckCoinValid(paymentAdd key.PaymentAddress, sharedRandom []byte, amount uint64) bool

func (CoinV1) Decrypt

func (c CoinV1) Decrypt(keySet *incognitokey.KeySet) (PlainCoin, error)

func (*CoinV1) DoesCoinBelongToKeySet

func (c *CoinV1) DoesCoinBelongToKeySet(keySet *incognitokey.KeySet) (bool, *operation.Point)

Check whether the utxo is from this address

func (*CoinV1) Encrypt

func (c *CoinV1) Encrypt(recipientTK key.TransmissionKey) *errhandler.PrivacyError

Encrypt returns a ciphertext encrypting for a coin using a hybrid cryptosystem, in which AES encryption scheme is used as a data encapsulation scheme, and ElGamal cryptosystem is used as a key encapsulation scheme.

func (CoinV1) GetAssetTag

func (c CoinV1) GetAssetTag() *operation.Point

func (CoinV1) GetCoinDetailEncrypted

func (c CoinV1) GetCoinDetailEncrypted() []byte

func (*CoinV1) GetCoinID

func (c *CoinV1) GetCoinID() [operation.Ed25519KeySize]byte

func (CoinV1) GetCommitment

func (c CoinV1) GetCommitment() *operation.Point

func (CoinV1) GetInfo

func (c CoinV1) GetInfo() []byte

func (CoinV1) GetKeyImage

func (c CoinV1) GetKeyImage() *operation.Point

func (CoinV1) GetPublicKey

func (c CoinV1) GetPublicKey() *operation.Point

func (CoinV1) GetRandomness

func (c CoinV1) GetRandomness() *operation.Scalar

func (CoinV1) GetSNDerivator

func (c CoinV1) GetSNDerivator() *operation.Scalar

func (CoinV1) GetShardID

func (c CoinV1) GetShardID() (uint8, error)

func (CoinV1) GetSharedConcealRandom

func (c CoinV1) GetSharedConcealRandom() *operation.Scalar

func (CoinV1) GetSharedRandom

func (c CoinV1) GetSharedRandom() *operation.Scalar

func (CoinV1) GetTxRandom

func (c CoinV1) GetTxRandom() *TxRandom

func (CoinV1) GetValue

func (c CoinV1) GetValue() uint64

func (CoinV1) GetVersion

func (c CoinV1) GetVersion() uint8

CoinV1 does not have index so return 0

func (*CoinV1) Init

func (c *CoinV1) Init() *CoinV1

Init (OutputCoin) initializes a output coin

func (CoinV1) IsEncrypted

func (c CoinV1) IsEncrypted() bool

func (*CoinV1) SetBytes

func (c *CoinV1) SetBytes(bytes []byte) error

SetBytes (OutputCoin) receives a coinBytes (in bytes array), and reverts coinBytes to a OutputCoin object

type CoinV2

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

CoinV2 is the struct that will be stored to db If not privacy, mask and amount will be the original randomness and value If has privacy, mask and amount will be as paper monero

func NewCoinCA

func NewCoinCA(p *CoinParams, tokenID *common.Hash) (*CoinV2, *operation.Point, error)

for confidential asset only

func NewCoinFromAmountAndReceiver

func NewCoinFromAmountAndReceiver(amount uint64, receiver key.PaymentAddress) (*CoinV2, error)

func NewCoinFromAmountAndTxRandomBytes

func NewCoinFromAmountAndTxRandomBytes(amount uint64, publicKey *operation.Point, txRandom *TxRandom, info []byte) *CoinV2

func NewCoinFromPaymentInfo

func NewCoinFromPaymentInfo(p *CoinParams) (*CoinV2, error)

func (CoinV2) Bytes

func (c CoinV2) Bytes() []byte

func (*CoinV2) CheckCoinValid

func (c *CoinV2) CheckCoinValid(paymentAdd key.PaymentAddress, sharedRandom []byte, amount uint64) bool

func (*CoinV2) ComputeCommitmentCA

func (coin *CoinV2) ComputeCommitmentCA() (*operation.Point, error)

func (*CoinV2) ConcealInputCoin

func (c *CoinV2) ConcealInputCoin()

Conceal the input coin of a transaction: keep only the keyImage

func (*CoinV2) ConcealOutputCoin

func (c *CoinV2) ConcealOutputCoin(additionalData *operation.Point) error

Conceal the amount of coin using the publicView of the receiver

  • AdditionalData: must be the publicView of the receiver

func (*CoinV2) Decrypt

func (c *CoinV2) Decrypt(keySet *incognitokey.KeySet) (PlainCoin, error)

Decrypt a coin using the corresponding KeySet

func (*CoinV2) DoesCoinBelongToKeySet

func (c *CoinV2) DoesCoinBelongToKeySet(keySet *incognitokey.KeySet) (bool, *operation.Point)

Check whether the utxo is from this keyset

func (CoinV2) GetAmount

func (c CoinV2) GetAmount() *operation.Scalar

func (CoinV2) GetAssetTag

func (c CoinV2) GetAssetTag() *operation.Point

func (CoinV2) GetCoinDetailEncrypted

func (c CoinV2) GetCoinDetailEncrypted() []byte

func (*CoinV2) GetCoinID

func (c *CoinV2) GetCoinID() [operation.Ed25519KeySize]byte

func (CoinV2) GetCommitment

func (c CoinV2) GetCommitment() *operation.Point

func (CoinV2) GetInfo

func (c CoinV2) GetInfo() []byte

func (CoinV2) GetKeyImage

func (c CoinV2) GetKeyImage() *operation.Point

func (CoinV2) GetPublicKey

func (c CoinV2) GetPublicKey() *operation.Point

func (CoinV2) GetRandomness

func (c CoinV2) GetRandomness() *operation.Scalar

func (CoinV2) GetSNDerivator

func (c CoinV2) GetSNDerivator() *operation.Scalar

Get SND will be nil for ver 2

func (CoinV2) GetShardID

func (c CoinV2) GetShardID() (uint8, error)

func (CoinV2) GetSharedConcealRandom

func (c CoinV2) GetSharedConcealRandom() *operation.Scalar

func (CoinV2) GetSharedRandom

func (c CoinV2) GetSharedRandom() *operation.Scalar

func (*CoinV2) GetTokenId

func (c *CoinV2) GetTokenId(keySet *incognitokey.KeySet, rawAssetTags map[string]*common.Hash) (*common.Hash, error)

GetTokenId attempts to retrieve the asset a CoinV2. Parameters:

  • keySet: the key set of the user, must contain an OTAKey
  • rawAssetTags: a pre-computed mapping from a raw assetTag to the tokenId (e.g, HashToPoint(PRV) => PRV).

func (CoinV2) GetTxRandom

func (c CoinV2) GetTxRandom() *TxRandom

func (CoinV2) GetTxRandomDetail

func (c CoinV2) GetTxRandomDetail() (*operation.Point, *operation.Point, uint32, error)

func (CoinV2) GetValue

func (c CoinV2) GetValue() uint64

func (CoinV2) GetVersion

func (c CoinV2) GetVersion() uint8

func (*CoinV2) HashH

func (c *CoinV2) HashH() *common.Hash

HashH returns the SHA3-256 hashing of coin bytes array

func (*CoinV2) Init

func (c *CoinV2) Init() *CoinV2

Init (OutputCoin) initializes a output coin

func (CoinV2) IsEncrypted

func (c CoinV2) IsEncrypted() bool

func (CoinV2) MarshalJSON

func (c CoinV2) MarshalJSON() ([]byte, error)

func (CoinV2) ParseKeyImageWithPrivateKey

func (c CoinV2) ParseKeyImageWithPrivateKey(privKey key.PrivateKey) (*operation.Point, error)

ParseKeyImageWithPrivateKey retrieves the keyImage of coin from the Master PrivateKey

func (CoinV2) ParsePrivateKeyOfCoin

func (c CoinV2) ParsePrivateKeyOfCoin(privKey key.PrivateKey) (*operation.Scalar, error)

ParsePrivateKeyOfCoin retrieves the private OTA key of coin from the Master PrivateKey

func (*CoinV2) RecomputeSharedSecret

func (coin *CoinV2) RecomputeSharedSecret(privateKey []byte) (*operation.Point, error)

this should be an input coin

func (*CoinV2) SetAmount

func (c *CoinV2) SetAmount(amount *operation.Scalar)

func (*CoinV2) SetAssetTag

func (c *CoinV2) SetAssetTag(at *operation.Point)

func (*CoinV2) SetBytes

func (c *CoinV2) SetBytes(coinBytes []byte) error

func (*CoinV2) SetCommitment

func (c *CoinV2) SetCommitment(commitment *operation.Point)

func (*CoinV2) SetInfo

func (c *CoinV2) SetInfo(b []byte)

func (*CoinV2) SetKeyImage

func (c *CoinV2) SetKeyImage(keyImage *operation.Point)

func (*CoinV2) SetPlainTokenID

func (coin *CoinV2) SetPlainTokenID(tokenID *common.Hash) error

func (*CoinV2) SetPublicKey

func (c *CoinV2) SetPublicKey(publicKey *operation.Point)

func (*CoinV2) SetRandomness

func (c *CoinV2) SetRandomness(mask *operation.Scalar)

func (*CoinV2) SetSharedConcealRandom

func (c *CoinV2) SetSharedConcealRandom(sharedConcealRandom *operation.Scalar)

func (*CoinV2) SetSharedRandom

func (c *CoinV2) SetSharedRandom(sharedRandom *operation.Scalar)

func (*CoinV2) SetTxRandom

func (c *CoinV2) SetTxRandom(txRandom *TxRandom)

func (*CoinV2) SetTxRandomDetail

func (c *CoinV2) SetTxRandomDetail(txConcealRandomPoint, txRandomPoint *operation.Point, index uint32)

func (*CoinV2) SetValue

func (c *CoinV2) SetValue(value uint64)

func (*CoinV2) SetVersion

func (c *CoinV2) SetVersion(uint8)

func (*CoinV2) UnmarshalJSON

func (c *CoinV2) UnmarshalJSON(data []byte) error

func (*CoinV2) ValidateAssetTag

func (coin *CoinV2) ValidateAssetTag(sharedSecret *operation.Point, tokenID *common.Hash) (bool, error)

type OTAReceiver

type OTAReceiver struct {
	PublicKey *operation.Point
	TxRandom  TxRandom
}

OTAReceiver holds the data necessary to send a coin to your receiver with privacy. It is somewhat equivalent in usage with PaymentAddress

func (OTAReceiver) Bytes

func (recv OTAReceiver) Bytes() ([]byte, error)

func (*OTAReceiver) FromAddress

func (recv *OTAReceiver) FromAddress(addr key.PaymentAddress) error

func (*OTAReceiver) FromString

func (recv *OTAReceiver) FromString(data string) error

FromString() returns a new OTAReceiver parsed from the input string, or error on failure

func (OTAReceiver) GetShardID

func (recv OTAReceiver) GetShardID() byte

func (OTAReceiver) IsValid

func (recv OTAReceiver) IsValid() bool

IsValid() checks the validity of this OTAReceiver (all referenced Points must be valid). Note that some sanity checks are already done when unmarshalling

func (OTAReceiver) MarshalJSON

func (recv OTAReceiver) MarshalJSON() ([]byte, error)

func (*OTAReceiver) SetBytes

func (recv *OTAReceiver) SetBytes(b []byte) error

func (OTAReceiver) String

func (recv OTAReceiver) String() (string, error)

String() marshals the OTAReceiver, then encodes it with base58

func (*OTAReceiver) UnmarshalJSON

func (recv *OTAReceiver) UnmarshalJSON(raw []byte) error

type PlainCoin

type PlainCoin interface {
	// Overide
	MarshalJSON() ([]byte, error)
	UnmarshalJSON(data []byte) error

	GetVersion() uint8
	GetCommitment() *operation.Point
	GetInfo() []byte
	GetPublicKey() *operation.Point
	GetValue() uint64
	GetKeyImage() *operation.Point
	GetRandomness() *operation.Scalar
	GetShardID() (uint8, error)
	GetSNDerivator() *operation.Scalar
	GetCoinDetailEncrypted() []byte
	IsEncrypted() bool
	GetTxRandom() *TxRandom
	GetSharedRandom() *operation.Scalar
	GetSharedConcealRandom() *operation.Scalar
	GetAssetTag() *operation.Point

	SetKeyImage(*operation.Point)
	SetPublicKey(*operation.Point)
	SetCommitment(*operation.Point)
	SetInfo([]byte)
	SetValue(uint64)
	SetRandomness(*operation.Scalar)

	// ParseKeyImage as Mlsag specification
	ParseKeyImageWithPrivateKey(key.PrivateKey) (*operation.Point, error)
	ParsePrivateKeyOfCoin(key.PrivateKey) (*operation.Scalar, error)

	ConcealOutputCoin(additionalData *operation.Point) error

	Bytes() []byte
	SetBytes([]byte) error
}

func NewPlainCoinFromByte

func NewPlainCoinFromByte(b []byte) (PlainCoin, error)

type PlainCoinV1

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

Coin represents a coin

func ArrayPlainCoinToPlainCoinV1

func ArrayPlainCoinToPlainCoinV1(inputCoins []PlainCoin) []*PlainCoinV1

func (*PlainCoinV1) Bytes

func (pc *PlainCoinV1) Bytes() []byte

Bytes converts a coin's details to a bytes array Each fields in coin is saved in len - body format

func (*PlainCoinV1) CommitAll

func (pc *PlainCoinV1) CommitAll() error

CommitAll commits a coin with 5 attributes include: public key, value, serial number derivator, shardID form last byte public key, randomness

func (*PlainCoinV1) ConcealOutputCoin

func (pc *PlainCoinV1) ConcealOutputCoin(additionalData *operation.Point) error

Conceal data leaving serialnumber

func (PlainCoinV1) GetAssetTag

func (pc PlainCoinV1) GetAssetTag() *operation.Point

func (PlainCoinV1) GetCoinDetailEncrypted

func (pc PlainCoinV1) GetCoinDetailEncrypted() []byte

func (PlainCoinV1) GetCommitment

func (pc PlainCoinV1) GetCommitment() *operation.Point

ver1 does not need to care for index

func (PlainCoinV1) GetInfo

func (pc PlainCoinV1) GetInfo() []byte

func (PlainCoinV1) GetKeyImage

func (pc PlainCoinV1) GetKeyImage() *operation.Point

func (PlainCoinV1) GetPublicKey

func (pc PlainCoinV1) GetPublicKey() *operation.Point

func (PlainCoinV1) GetRandomness

func (pc PlainCoinV1) GetRandomness() *operation.Scalar

func (PlainCoinV1) GetSNDerivator

func (pc PlainCoinV1) GetSNDerivator() *operation.Scalar

func (*PlainCoinV1) GetShardID

func (pc *PlainCoinV1) GetShardID() (uint8, error)

func (PlainCoinV1) GetSharedConcealRandom

func (pc PlainCoinV1) GetSharedConcealRandom() *operation.Scalar

func (PlainCoinV1) GetSharedRandom

func (pc PlainCoinV1) GetSharedRandom() *operation.Scalar

func (PlainCoinV1) GetTxRandom

func (pc PlainCoinV1) GetTxRandom() *TxRandom

func (PlainCoinV1) GetValue

func (pc PlainCoinV1) GetValue() uint64

func (*PlainCoinV1) GetVersion

func (*PlainCoinV1) GetVersion() uint8

func (*PlainCoinV1) HashH

func (pc *PlainCoinV1) HashH() *common.Hash

HashH returns the SHA3-256 hashing of coin bytes array

func (*PlainCoinV1) Init

func (pc *PlainCoinV1) Init() *PlainCoinV1

Init (Coin) initializes a coin

func (PlainCoinV1) IsEncrypted

func (pc PlainCoinV1) IsEncrypted() bool

func (PlainCoinV1) MarshalJSON

func (pc PlainCoinV1) MarshalJSON() ([]byte, error)

MarshalJSON (CoinV1) converts coin to bytes array, base58 check encode that bytes array into string json.Marshal the string

func (*PlainCoinV1) ParseCoinObjectToInputCoin

func (pc *PlainCoinV1) ParseCoinObjectToInputCoin(coinObj CoinObject) error

SetBytes (InputCoin) receives a coinBytes (in bytes array), and reverts coinBytes to a InputCoin object

func (PlainCoinV1) ParseKeyImageWithPrivateKey

func (pc PlainCoinV1) ParseKeyImageWithPrivateKey(privKey key.PrivateKey) (*operation.Point, error)

func (PlainCoinV1) ParsePrivateKeyOfCoin

func (pc PlainCoinV1) ParsePrivateKeyOfCoin(privKey key.PrivateKey) (*operation.Scalar, error)

For ver1, privateKey of coin is privateKey of user

func (*PlainCoinV1) SetBytes

func (pc *PlainCoinV1) SetBytes(coinBytes []byte) error

SetBytes receives a coinBytes (in bytes array), and reverts coinBytes to a Coin object

func (*PlainCoinV1) SetCommitment

func (pc *PlainCoinV1) SetCommitment(v *operation.Point)

func (*PlainCoinV1) SetInfo

func (pc *PlainCoinV1) SetInfo(v []byte)

func (*PlainCoinV1) SetKeyImage

func (pc *PlainCoinV1) SetKeyImage(v *operation.Point)

func (*PlainCoinV1) SetPublicKey

func (pc *PlainCoinV1) SetPublicKey(v *operation.Point)

func (*PlainCoinV1) SetRandomness

func (pc *PlainCoinV1) SetRandomness(v *operation.Scalar)

func (*PlainCoinV1) SetSNDerivator

func (pc *PlainCoinV1) SetSNDerivator(v *operation.Scalar)

func (*PlainCoinV1) SetValue

func (pc *PlainCoinV1) SetValue(v uint64)

func (*PlainCoinV1) UnmarshalJSON

func (pc *PlainCoinV1) UnmarshalJSON(data []byte) error

UnmarshalJSON (Coin) receives bytes array of coin (it was be MarshalJSON before), json.Unmarshal the bytes array to string base58 check decode that string to bytes array and set bytes array to coin

type TxRandom

type TxRandom [TxRandomGroupSize]byte

func NewOTAFromReceiver

func NewOTAFromReceiver(receiver key.PaymentAddress) (*operation.Point, *TxRandom, error)

func NewTxRandom

func NewTxRandom() *TxRandom

func ParseOTAInfoFromString

func ParseOTAInfoFromString(pubKeyStr, txRandomStr string) (*operation.Point, *TxRandom, error)

func (TxRandom) Bytes

func (t TxRandom) Bytes() []byte

func (TxRandom) GetIndex

func (t TxRandom) GetIndex() (uint32, error)

func (TxRandom) GetTxConcealRandomPoint

func (t TxRandom) GetTxConcealRandomPoint() (*operation.Point, error)

func (TxRandom) GetTxOTARandomPoint

func (t TxRandom) GetTxOTARandomPoint() (*operation.Point, error)

func (*TxRandom) SetBytes

func (t *TxRandom) SetBytes(b []byte) error

func (*TxRandom) SetIndex

func (t *TxRandom) SetIndex(index uint32)

func (*TxRandom) SetTxConcealRandomPoint

func (t *TxRandom) SetTxConcealRandomPoint(txConcealRandom *operation.Point)

func (*TxRandom) SetTxOTARandomPoint

func (t *TxRandom) SetTxOTARandomPoint(txRandom *operation.Point)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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