Documentation ¶
Index ¶
- Constants
- Variables
- func ArrayToSlice(array [Ed25519KeySize]byte) []byte
- func CheckDuplicateScalarArray(arr []*Scalar) bool
- func Compare(sca, scb *Scalar) int
- func ConvertIntToBinary(inum int, n int) []byte
- func ConvertScalarArrayToBigIntArray(scalarArr []*Scalar) []*big.Int
- func HybridDecrypt(ciphertext *HybridCipherText, privateKey *Scalar) (msg []byte, err error)
- func IsPointEqual(pa *Point, pb *Point) bool
- func IsScalarEqual(sc1, sc2 *Scalar) bool
- func RandBytes(length int) []byte
- func Reverse(x C25519.Key) (result C25519.Key)
- func ScalarToBigInt(sc *Scalar) *big.Int
- func SliceToArray(slice []byte) [Ed25519KeySize]byte
- type Coin
- func (coin *Coin) Bytes() []byte
- func (coin *Coin) CommitAll() error
- func (coin Coin) GetCoinCommitment() *Point
- func (coin Coin) GetInfo() []byte
- func (coin *Coin) GetPubKeyLastByte() byte
- func (coin Coin) GetPublicKey() *Point
- func (coin Coin) GetRandomness() *Scalar
- func (coin Coin) GetSNDerivator() *Scalar
- func (coin Coin) GetSerialNumber() *Point
- func (coin Coin) GetValue() uint64
- func (coin *Coin) HashH() *common.Hash
- func (coin *Coin) Init() *Coin
- func (coin Coin) MarshalJSON() ([]byte, error)
- func (coin *Coin) SetBytes(coinBytes []byte) error
- func (coin *Coin) SetCoinCommitment(v *Point)
- func (coin *Coin) SetInfo(v []byte)
- func (coin *Coin) SetPublicKey(v *Point)
- func (coin *Coin) SetRandomness(v *Scalar)
- func (coin *Coin) SetSNDerivator(v *Scalar)
- func (coin *Coin) SetSerialNumber(v *Point)
- func (coin *Coin) SetValue(v uint64)
- func (coin *Coin) UnmarshalJSON(data []byte) error
- type CoinObject
- type HybridCipherText
- func (ciphertext HybridCipherText) Bytes() []byte
- func (ciphertext HybridCipherText) GetMsgEncrypted() []byte
- func (ciphertext HybridCipherText) GetSymKeyEncrypted() []byte
- func (ciphertext HybridCipherText) IsNil() bool
- func (hybridCipherText HybridCipherText) MarshalJSON() ([]byte, error)
- func (ciphertext *HybridCipherText) SetBytes(bytes []byte) error
- func (hybridCipherText *HybridCipherText) UnmarshalJSON(data []byte) error
- type InputCoin
- type OutputCoin
- func (outputCoin *OutputCoin) Bytes() []byte
- func (outputCoin *OutputCoin) Decrypt(viewingKey ViewingKey) *PrivacyError
- func (outputCoin *OutputCoin) Encrypt(recipientTK TransmissionKey) *PrivacyError
- func (outputCoin *OutputCoin) Init() *OutputCoin
- func (outputCoin *OutputCoin) SetBytes(bytes []byte) error
- type PaymentAddress
- type PaymentInfo
- type PedersenCommitment
- type Point
- func (p *Point) Add(pa, pb *Point) *Point
- func (p *Point) AddPedersen(a *Scalar, A *Point, b *Scalar, B *Point) *Point
- func (p *Point) AddPedersenCached(a *Scalar, APreCompute [8]C25519.CachedGroupElement, b *Scalar, ...) *Point
- func (p *Point) Derive(pa *Point, a *Scalar, b *Scalar) *Point
- func (p *Point) FromBytes(b [Ed25519KeySize]byte) (*Point, error)
- func (p *Point) FromBytesS(b []byte) (*Point, error)
- func (p Point) GetKey() C25519.Key
- func (p *Point) Identity() *Point
- func (p *Point) InvertScalarMult(pa *Point, a *Scalar) *Point
- func (p *Point) InvertScalarMultBase(a *Scalar) *Point
- func (p Point) IsIdentity() bool
- func (p Point) MarshalText() []byte
- func (p *Point) MultiScalarMult(scalarLs []*Scalar, pointLs []*Point) *Point
- func (p *Point) MultiScalarMultCached(scalarLs []*Scalar, pointPreComputedLs [][8]C25519.CachedGroupElement) *Point
- func (p Point) PointValid() bool
- func (p *Point) ScalarMult(pa *Point, a *Scalar) *Point
- func (p *Point) ScalarMultBase(a *Scalar) *Point
- func (p *Point) Set(q *Point) *Point
- func (p *Point) SetKey(a *C25519.Key) (*Point, error)
- func (p *Point) Sub(pa, pb *Point) *Point
- func (p Point) ToBytes() [Ed25519KeySize]byte
- func (p Point) ToBytesS() []byte
- func (p *Point) UnmarshalText(data []byte) (*Point, error)
- type Poly
- type PrivacyError
- type PrivateKey
- type PublicKey
- type ReceivingKey
- type Scalar
- func (sc *Scalar) Add(a, b *Scalar) *Scalar
- func (sc *Scalar) Exp(a *Scalar, v uint64) *Scalar
- func (sc *Scalar) FromBytes(b [Ed25519KeySize]byte) *Scalar
- func (sc *Scalar) FromBytesS(b []byte) *Scalar
- func (sc *Scalar) FromUint64(i uint64) *Scalar
- func (sc Scalar) GetKey() C25519.Key
- func (sc *Scalar) Invert(a *Scalar) *Scalar
- func (sc *Scalar) IsOne() bool
- func (sc *Scalar) IsZero() bool
- func (sc Scalar) MarshalText() []byte
- func (sc *Scalar) Mul(a, b *Scalar) *Scalar
- func (sc *Scalar) MulAdd(a, b, c *Scalar) *Scalar
- func (sc *Scalar) ScalarValid() bool
- func (sc *Scalar) Set(a *Scalar) *Scalar
- func (sc *Scalar) SetKey(a *C25519.Key) (*Scalar, error)
- func (sc Scalar) String() string
- func (sc *Scalar) Sub(a, b *Scalar) *Scalar
- func (sc Scalar) ToBytes() [Ed25519KeySize]byte
- func (sc Scalar) ToBytesS() []byte
- func (sc *Scalar) ToUint64() uint64
- func (sc *Scalar) UnmarshalText(data []byte) (*Scalar, error)
- type SchnSignature
- type SchnorrPrivateKey
- type SchnorrPublicKey
- type TransmissionKey
- type ViewingKey
Constants ¶
const ( Ed25519KeySize = 32 AESKeySize = 32 CommitmentRingSize = 8 CommitmentRingSizeExp = 3 CStringBulletProof = "bulletproof" CStringBurnAddress = "burningaddress" FixedRandomnessString = "fixedrandomness" )
const ( UnexpectedErr = iota InvalidOutputValue MarshalPaymentProofErr UnmarshalPaymentProofErr SetBytesProofErr EncryptOutputCoinErr DecryptOutputCoinErr DecompressTransmissionKeyErr VerifySerialNumberNoPrivacyProofFailedErr VerifyCoinCommitmentInputFailedErr VerifyCoinCommitmentOutputFailedErr VerifyAmountNoPrivacyFailedErr VerifyOneOutOfManyProofFailedErr VerifySerialNumberPrivacyProofFailedErr VerifyAggregatedProofFailedErr VerifyAmountPrivacyFailedErr CalInnerProductErr ProveSerialNumberNoPrivacyErr ProveOneOutOfManyErr ProveSerialNumberPrivacyErr ProveAggregatedRangeErr InvalidInputToSetBytesErr CommitNewOutputCoinNoPrivacyErr ConvertMultiSigToBytesErr SignMultiSigErr InvalidLengthMultiSigErr InvalidMultiSigErr )
const ( PedersenPrivateKeyIndex = byte(0x00) PedersenValueIndex = byte(0x01) PedersenSndIndex = byte(0x02) PedersenShardIDIndex = byte(0x03) PedersenRandomnessIndex = byte(0x04) )
const (
MaxSizeInfoCoin = 255 // byte
)
Variables ¶
var ErrCodeMessage = map[int]struct { Code int Message string }{ UnexpectedErr: {-9000, "Unexpected error"}, InvalidOutputValue: {-9001, "Invalid output value"}, MarshalPaymentProofErr: {-9002, "Marshal payment proof error"}, UnmarshalPaymentProofErr: {-9003, "Unmarshal payment proof error"}, SetBytesProofErr: {-9004, "Set bytes payment proof error"}, EncryptOutputCoinErr: {-9005, "Encrypt output coins error"}, DecryptOutputCoinErr: {-9006, "Decrypt output coins error"}, DecompressTransmissionKeyErr: {-9007, "Can not decompress transmission key error"}, CalInnerProductErr: {-9008, "Calculate inner product between two vectors error"}, InvalidInputToSetBytesErr: {-9009, "Length of input data is zero, can not set bytes"}, CommitNewOutputCoinNoPrivacyErr: {-9010, "Can not commit output coin's details when creating tx without privacy"}, ConvertMultiSigToBytesErr: {-9011, "Can not convert multi sig to bytes array"}, SignMultiSigErr: {-9012, "Can not sign multi sig"}, InvalidLengthMultiSigErr: {-9013, "Invalid length of multi sig signature"}, InvalidMultiSigErr: {-9014, "invalid multiSig for converting to bytes array"}, ProveSerialNumberNoPrivacyErr: {-9100, "Proving serial number no privacy proof error"}, ProveOneOutOfManyErr: {-9101, "Proving one out of many proof error"}, ProveSerialNumberPrivacyErr: {-9102, "Proving serial number privacy proof error"}, ProveAggregatedRangeErr: {-9103, "Proving aggregated range proof error"}, VerifySerialNumberNoPrivacyProofFailedErr: {-9201, "Verify serial number no privacy proof failed"}, VerifyCoinCommitmentInputFailedErr: {-9202, "Verify coin commitment of input coin failed"}, VerifyCoinCommitmentOutputFailedErr: {-9203, "Verify coin commitment of output coin failed"}, VerifyAmountNoPrivacyFailedErr: {-9204, "Sum of input coins' amount is not equal sum of output coins' amount"}, VerifyOneOutOfManyProofFailedErr: {-9205, "Verify one out of many proof failed"}, VerifySerialNumberPrivacyProofFailedErr: {-9206, "Verify serial number privacy proof failed"}, VerifyAggregatedProofFailedErr: {-9207, "Verify aggregated proof failed"}, VerifyAmountPrivacyFailedErr: {-9208, "Sum of input coins' amount is not equal sum of output coins' amount when creating private tx"}, }
var FixedRandomnessShardID = new(Scalar).FromBytesS([]byte{0x60, 0xa2, 0xab, 0x35, 0x26, 0x9, 0x97, 0x7c, 0x6b, 0xe1, 0xba, 0xec, 0xbf, 0x64, 0x27, 0x2, 0x6a, 0x9c, 0xe8, 0x10, 0x9e, 0x93, 0x4a, 0x0, 0x47, 0x83, 0x15, 0x48, 0x63, 0xeb, 0xda, 0x6})
FixedRandomnessShardID is fixed randomness for shardID commitment from param.BCHeightBreakPointFixRandShardCM is result from HashToScalar([]byte(FixedRandomnessString))
var LInt = new(big.Int).SetBytes([]byte{0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0xde, 0xf9, 0xde, 0xa2, 0xf7, 0x9c, 0xd6, 0x58, 0x12, 0x63, 0x1a, 0x5c, 0xf5, 0xd3, 0xed})
var PedCom = newPedersenParams()
Functions ¶
func ArrayToSlice ¶
func ArrayToSlice(array [Ed25519KeySize]byte) []byte
func ConvertIntToBinary ¶
ConvertIntToBinary represents a integer number in binary array with little endian with size n
func HybridDecrypt ¶
func HybridDecrypt(ciphertext *HybridCipherText, privateKey *Scalar) (msg []byte, err error)
hybridDecrypt_Old receives a ciphertext and privateKey it decrypts aesKeyPoint, using ElGamal encryption with privateKey Using X-coordinate of aesKeyPoint to decrypts message
func IsPointEqual ¶
func IsScalarEqual ¶
func ScalarToBigInt ¶
func SliceToArray ¶
func SliceToArray(slice []byte) [Ed25519KeySize]byte
Types ¶
type Coin ¶
type Coin struct {
// contains filtered or unexported fields
}
Coin represents a coin
func (*Coin) Bytes ¶
Bytes converts a coin's details to a bytes array Each fields in coin is saved in len - body format
func (*Coin) CommitAll ¶
CommitAll commits a coin with 5 attributes include: public key, value, serial number derivator, shardID form last byte public key, randomness
func (Coin) GetCoinCommitment ¶
func (*Coin) GetPubKeyLastByte ¶
GetPubKeyLastByte returns the last byte of public key
func (Coin) GetRandomness ¶
func (Coin) GetSNDerivator ¶
func (Coin) GetSerialNumber ¶
func (Coin) MarshalJSON ¶
MarshalJSON (Coin) converts coin to bytes array, base58 check encode that bytes array into string json.Marshal the string
func (*Coin) SetBytes ¶
SetBytes receives a coinBytes (in bytes array), and reverts coinBytes to a Coin object
func (*Coin) SetCoinCommitment ¶
func (*Coin) SetPublicKey ¶
func (*Coin) SetRandomness ¶
func (*Coin) SetSNDerivator ¶
func (*Coin) SetSerialNumber ¶
func (*Coin) UnmarshalJSON ¶
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 CoinObject ¶
type HybridCipherText ¶
type HybridCipherText struct {
// contains filtered or unexported fields
}
hybridCipherText_Old represents to hybridCipherText_Old for Hybrid encryption Hybrid encryption uses AES scheme to encrypt message with arbitrary size and uses Elgamal encryption to encrypt AES key
func HybridEncrypt ¶
func HybridEncrypt(msg []byte, publicKey *Point) (ciphertext *HybridCipherText, err error)
hybridEncrypt_Old encrypts message with any size, using Publickey to encrypt hybridEncrypt_Old generates AES key by randomize an elliptic point aesKeyPoint and get X-coordinate using AES key to encrypt message After that, using ElGamal encryption encrypt aesKeyPoint using publicKey
func (HybridCipherText) Bytes ¶
func (ciphertext HybridCipherText) Bytes() []byte
Bytes converts ciphertext to bytes array if ciphertext is nil, return empty byte array
func (HybridCipherText) GetMsgEncrypted ¶
func (ciphertext HybridCipherText) GetMsgEncrypted() []byte
func (HybridCipherText) GetSymKeyEncrypted ¶
func (ciphertext HybridCipherText) GetSymKeyEncrypted() []byte
func (HybridCipherText) IsNil ¶
func (ciphertext HybridCipherText) IsNil() bool
isNil check whether ciphertext is nil or not
func (HybridCipherText) MarshalJSON ¶
func (hybridCipherText HybridCipherText) MarshalJSON() ([]byte, error)
func (*HybridCipherText) SetBytes ¶
func (ciphertext *HybridCipherText) SetBytes(bytes []byte) error
SetBytes reverts bytes array to hybridCipherText_Old
func (*HybridCipherText) UnmarshalJSON ¶
func (hybridCipherText *HybridCipherText) UnmarshalJSON(data []byte) error
type InputCoin ¶
type InputCoin struct {
CoinDetails *Coin
}
InputCoin represents a input coin of transaction
func (*InputCoin) Bytes ¶
Bytes (InputCoin) converts a input coin's details to a bytes array Each fields in coin is saved in len - body format
func (*InputCoin) ParseCoinObjectToInputCoin ¶
func (inputCoin *InputCoin) ParseCoinObjectToInputCoin(coinObj CoinObject) error
SetBytes (InputCoin) receives a coinBytes (in bytes array), and reverts coinBytes to a InputCoin object
type OutputCoin ¶
type OutputCoin struct { CoinDetails *Coin CoinDetailsEncrypted *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 (*OutputCoin) Bytes ¶
func (outputCoin *OutputCoin) 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 (*OutputCoin) Decrypt ¶
func (outputCoin *OutputCoin) Decrypt(viewingKey ViewingKey) *PrivacyError
Decrypt decrypts a ciphertext encrypting for coin with recipient's receiving key
func (*OutputCoin) Encrypt ¶
func (outputCoin *OutputCoin) Encrypt(recipientTK TransmissionKey) *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 (*OutputCoin) Init ¶
func (outputCoin *OutputCoin) Init() *OutputCoin
Init (OutputCoin) initializes a output coin
func (*OutputCoin) SetBytes ¶
func (outputCoin *OutputCoin) SetBytes(bytes []byte) error
SetBytes (OutputCoin) receives a coinBytes (in bytes array), and reverts coinBytes to a OutputCoin object
type PaymentAddress ¶
type PaymentAddress struct { Pk PublicKey // 33 bytes, use to receive coin Tk TransmissionKey // 33 bytes, use to encrypt pointByte }
PaymentAddress is an address of a payee
func GeneratePaymentAddress ¶
func GeneratePaymentAddress(privateKey []byte) PaymentAddress
GeneratePaymentAddress generates a payment address corresponding to a spending key
func (*PaymentAddress) Bytes ¶
func (addr *PaymentAddress) Bytes() []byte
Bytes converts payment address to bytes array
func (*PaymentAddress) SetBytes ¶
func (addr *PaymentAddress) SetBytes(bytes []byte) *PaymentAddress
SetBytes reverts bytes array to payment address
func (PaymentAddress) String ¶
func (addr PaymentAddress) String() string
String encodes a payment address as a hex string
type PaymentInfo ¶
type PaymentInfo struct { PaymentAddress PaymentAddress Amount uint64 Message []byte // 512 bytes }
PaymentInfo contains an address of a payee and a value of coins he/she will receive
type PedersenCommitment ¶
type PedersenCommitment struct {
G []*Point // generators
}
PedersenCommitment represents the parameters for the commitment
func (PedersenCommitment) CommitAtIndex ¶
func (com PedersenCommitment) CommitAtIndex(value, rand *Scalar, index byte) *Point
CommitAtIndex commits specific value with index and returns 34 bytes g^v x h^rand
type Point ¶
type Point struct {
// contains filtered or unexported fields
}
var GBase, HBase *Point
func HashToPoint ¶
func HashToPointFromIndex ¶
func RandomPoint ¶
func RandomPoint() *Point
func (*Point) AddPedersen ¶
aA + bB
func (*Point) AddPedersenCached ¶
func (p *Point) AddPedersenCached(a *Scalar, APreCompute [8]C25519.CachedGroupElement, b *Scalar, BPreCompute [8]C25519.CachedGroupElement) *Point
func (*Point) InvertScalarMultBase ¶
func (Point) IsIdentity ¶
func (Point) MarshalText ¶
func (*Point) MultiScalarMult ¶
func (*Point) MultiScalarMultCached ¶
func (p *Point) MultiScalarMultCached(scalarLs []*Scalar, pointPreComputedLs [][8]C25519.CachedGroupElement) *Point
func (Point) PointValid ¶
func (*Point) ScalarMultBase ¶
does a * G where a is a scalar and G is the curve basepoint
func (Point) ToBytes ¶
func (p Point) ToBytes() [Ed25519KeySize]byte
type Poly ¶
Data structure for a polynomial Just an array in Reverse f(x) = 3x^3 + 2x + 1 => [1 2 0 3]
type PrivacyError ¶
func NewPrivacyErr ¶
func NewPrivacyErr(key int, err error) *PrivacyError
func (PrivacyError) Error ¶
func (e PrivacyError) Error() string
func (PrivacyError) GetCode ¶
func (e PrivacyError) GetCode() int
type PrivateKey ¶
type PrivateKey []byte
32-byte spending key
func GeneratePrivateKey ¶
func GeneratePrivateKey(seed []byte) PrivateKey
GeneratePrivateKey generates a random 32-byte spending key
type PublicKey ¶
type PublicKey []byte
32-byte public key
func GeneratePublicKey ¶
GeneratePublicKey computes a 32-byte public-key corresponding to a spending key
type ReceivingKey ¶
type ReceivingKey []byte
32-byte receiving key
func GenerateReceivingKey ¶
func GenerateReceivingKey(privateKey []byte) ReceivingKey
GenerateReceivingKey generates a 32-byte receiving key
type Scalar ¶
type Scalar struct {
// contains filtered or unexported fields
}
func BigIntToScalar ¶
func ConvertUint64ToBinary ¶
ConvertIntToBinary represents a integer number in binary
func HashToScalar ¶
func RandomScalar ¶
func RandomScalar() *Scalar
func (*Scalar) FromBytesS ¶
func (*Scalar) FromUint64 ¶
func (Scalar) MarshalText ¶
func (*Scalar) ScalarValid ¶
func (Scalar) ToBytes ¶
func (sc Scalar) ToBytes() [Ed25519KeySize]byte
type SchnSignature ¶
type SchnSignature struct {
// contains filtered or unexported fields
}
SchnSignature represents Schnorr Signature
func (SchnSignature) Bytes ¶
func (sig SchnSignature) Bytes() []byte
func (*SchnSignature) SetBytes ¶
func (sig *SchnSignature) SetBytes(bytes []byte) error
type SchnorrPrivateKey ¶
type SchnorrPrivateKey struct {
// contains filtered or unexported fields
}
SchnorrPrivateKey represents Schnorr Privatekey
func (SchnorrPrivateKey) GetPublicKey ¶
func (schnPrivKey SchnorrPrivateKey) GetPublicKey() *SchnorrPublicKey
func (*SchnorrPrivateKey) Set ¶
func (privateKey *SchnorrPrivateKey) Set(sk *Scalar, r *Scalar)
Set sets Schnorr private key
func (SchnorrPrivateKey) Sign ¶
func (privateKey SchnorrPrivateKey) Sign(data []byte) (*SchnSignature, error)
Sign is function which using for signing on hash array by private key
type SchnorrPublicKey ¶
type SchnorrPublicKey struct {
// contains filtered or unexported fields
}
SchnorrPublicKey represents Schnorr Publickey PK = G^SK + H^R
func (SchnorrPublicKey) GetPublicKey ¶
func (schnorrPubKey SchnorrPublicKey) GetPublicKey() *Point
func (*SchnorrPublicKey) Set ¶
func (publicKey *SchnorrPublicKey) Set(pk *Point)
Set sets Schnorr public key
func (SchnorrPublicKey) Verify ¶
func (publicKey SchnorrPublicKey) Verify(signature *SchnSignature, data []byte) bool
Verify is function which using for verify that the given signature was signed by by privatekey of the public key
type TransmissionKey ¶
type TransmissionKey []byte
32-byte transmission key
func GenerateTransmissionKey ¶
func GenerateTransmissionKey(receivingKey []byte) TransmissionKey
GenerateTransmissionKey computes a 33-byte transmission key corresponding to a receiving key
type ViewingKey ¶
type ViewingKey struct { Pk PublicKey // 33 bytes, use to receive coin Rk ReceivingKey // 32 bytes, use to decrypt pointByte }
ViewingKey is a public/private key pair to encrypt coins in an outgoing transaction and decrypt coins in an incoming transaction
func GenerateViewingKey ¶
func GenerateViewingKey(privateKey []byte) ViewingKey
GenerateViewingKey generates a viewingKey corresponding to a spending key