Documentation
¶
Index ¶
- Constants
- Variables
- func BLSKeyGen(seed []byte) (*big.Int, *bn256.G2)
- func BLSPKGen(sk *big.Int) *bn256.G2
- func BLSSKGen(seed []byte) *big.Int
- func BridgeKeyGen(seed []byte) (ecdsa.PrivateKey, ecdsa.PublicKey)
- func BridgePKBytes(pubKey *ecdsa.PublicKey) []byte
- func DecodeECDSASig(sigStr string) (v byte, r []byte, s []byte, err error)
- type CommitteeKeyString
- type CommitteePublicKey
- func (pubKey *CommitteePublicKey) Bytes() ([]byte, error)
- func (pubKey *CommitteePublicKey) CheckSanityData() bool
- func (pubKey *CommitteePublicKey) FromBase58(keyString string) error
- func (pubKey *CommitteePublicKey) FromBytes(keyBytes []byte) error
- func (pubKey *CommitteePublicKey) FromString(keyString string) error
- func (pubKey *CommitteePublicKey) GetIncKeyBase58() string
- func (pubKey *CommitteePublicKey) GetMiningKey(schemeName string) ([]byte, error)
- func (pubKey *CommitteePublicKey) GetMiningKeyBase58(schemeName string) string
- func (pubKey *CommitteePublicKey) GetNormalKey() []byte
- func (pubKey *CommitteePublicKey) IsEqual(target CommitteePublicKey) bool
- func (pubKey *CommitteePublicKey) IsEqualMiningPubKey(consensusName string, k *CommitteePublicKey) bool
- func (pubKey *CommitteePublicKey) RawBytes() ([]byte, error)
- func (pubKey *CommitteePublicKey) ToBase58() (string, error)
- type Error
- type KeySet
- type OTAKey
- type PaymentAddress
- func (addr *PaymentAddress) Bytes() []byte
- func (addr PaymentAddress) GetOTAPublicKey() *crypto.Point
- func (addr PaymentAddress) GetPublicSpend() *crypto.Point
- func (addr PaymentAddress) GetPublicView() *crypto.Point
- func (addr *PaymentAddress) SetBytes(bytes []byte) error
- func (addr PaymentAddress) String() string
- type PaymentInfo
- type PrivateKey
- type PrivateOTAKey
- type PublicKey
- type PublicOTAKey
- type ReceivingKey
- type TransmissionKey
- type ViewingKey
Constants ¶
const ( InvalidPrivateKeyErr = iota B58DecodePubKeyErr B58DecodeSigErr B58ValidateErr InvalidDataValidateErr SignDataB58Err InvalidDataSignErr InvalidVerificationKeyErr DecodeFromStringErr SignError JSONError )
const (
CBridgeSigSz = 65
)
Variables ¶
var ErrCodeMessage = map[int]struct { Code int Message string }{ InvalidPrivateKeyErr: {-201, "Private key is invalid"}, B58DecodePubKeyErr: {-202, "Base58 decode pub key error"}, B58DecodeSigErr: {-203, "Base58 decode signature error"}, B58ValidateErr: {-204, "Base58 validate data error"}, InvalidDataValidateErr: {-205, "Validated base58 data is invalid"}, SignDataB58Err: {-206, "Signing B58 data error"}, InvalidDataSignErr: {-207, "Signed data is invalid"}, InvalidVerificationKeyErr: {-208, "Verification key is invalid"}, DecodeFromStringErr: {-209, "Decode key set from string error"}, SignError: {-210, "Can not sign data"}, JSONError: {-211, "JSON Marshal, Unmarshal error"}, }
ErrCodeMessage represents a key-related error.
Functions ¶
func BridgeKeyGen ¶
func BridgeKeyGen(seed []byte) (ecdsa.PrivateKey, ecdsa.PublicKey)
BridgeKeyGen generates a pair of ecdsa.PrivateKey and ecdsa.PublicKey from the given seed.
func BridgePKBytes ¶
BridgePKBytes returns the compressed version of a ecdsa.PublicKey.
Types ¶
type CommitteeKeyString ¶
CommitteeKeyString is the string alternative to a CommitteePublicKey.
type CommitteePublicKey ¶
CommitteePublicKey consists of public keys of a user used in the consensus protocol. A CommitteePublicKey has
- IncPubKey: the public key of the user.
- MiningPubKey: a list of keys used in the consensus protocol.
- BLS: used to sign blocks, create votes inside the Incognito network.
- ECDSA: used to sign blocks for interacting with outside blockchain networks.
func NewCommitteeKeyFromSeed ¶
func NewCommitteeKeyFromSeed(seed, incPubKey []byte) (CommitteePublicKey, error)
NewCommitteeKeyFromSeed creates a new NewCommitteeKeyFromSeed given a seed and a public key.
func NewCommitteePublicKey ¶
func NewCommitteePublicKey() *CommitteePublicKey
func (*CommitteePublicKey) Bytes ¶
func (pubKey *CommitteePublicKey) Bytes() ([]byte, error)
Bytes returns the JSON-marshalled data of a CommitteePublicKey.
func (*CommitteePublicKey) CheckSanityData ¶
func (pubKey *CommitteePublicKey) CheckSanityData() bool
CheckSanityData checks sanity of a CommitteePublicKey.
func (*CommitteePublicKey) FromBase58 ¶
func (pubKey *CommitteePublicKey) FromBase58(keyString string) error
FromBase58 recovers the CommitteePublicKey from its base58-representation.
func (*CommitteePublicKey) FromBytes ¶
func (pubKey *CommitteePublicKey) FromBytes(keyBytes []byte) error
FromBytes sets raw-data to a CommitteePublicKey.
func (*CommitteePublicKey) FromString ¶
func (pubKey *CommitteePublicKey) FromString(keyString string) error
FromString sets a CommitteePublicKey from a string.
func (*CommitteePublicKey) GetIncKeyBase58 ¶
func (pubKey *CommitteePublicKey) GetIncKeyBase58() string
GetIncKeyBase58 returns the base58-encoded public key of a CommitteePublicKey.
func (*CommitteePublicKey) GetMiningKey ¶
func (pubKey *CommitteePublicKey) GetMiningKey(schemeName string) ([]byte, error)
GetMiningKey returns the mining key of a CommitteePublicKey given the consensus scheme.
func (*CommitteePublicKey) GetMiningKeyBase58 ¶
func (pubKey *CommitteePublicKey) GetMiningKeyBase58(schemeName string) string
GetMiningKeyBase58 returns the base58-encoded mining key of a CommitteePublicKey given the consensus scheme.
func (*CommitteePublicKey) GetNormalKey ¶
func (pubKey *CommitteePublicKey) GetNormalKey() []byte
GetNormalKey returns the public key of a CommitteePublicKey.
func (*CommitteePublicKey) IsEqual ¶
func (pubKey *CommitteePublicKey) IsEqual(target CommitteePublicKey) bool
IsEqual checks if a CommitteePublicKey is equal to the input CommitteePublicKey.
func (*CommitteePublicKey) IsEqualMiningPubKey ¶
func (pubKey *CommitteePublicKey) IsEqualMiningPubKey(consensusName string, k *CommitteePublicKey) bool
IsEqualMiningPubKey checks if a CommitteePublicKey is equal to another CommitteePublicKey w.r.t the given consensus name.
func (*CommitteePublicKey) RawBytes ¶
func (pubKey *CommitteePublicKey) RawBytes() ([]byte, error)
RawBytes returns the raw-byte data of a CommitteePublicKey.
func (*CommitteePublicKey) ToBase58 ¶
func (pubKey *CommitteePublicKey) ToBase58() (string, error)
ToBase58 returns the base58-encoded representation of a CommitteePublicKey
type Error ¶
Error represents a wrapped error when using the key package.
type KeySet ¶
type KeySet struct { PrivateKey PrivateKey //Master Private key PaymentAddress PaymentAddress //Payment address for sending coins ReadonlyKey ViewingKey //ViewingKey for retrieving the amount of coin (both V1 + V2) as well as the asset tag (V2 ONLY) OTAKey OTAKey //OTAKey is for recovering one time addresses: ONLY in V2 }
KeySet consists of the following fields - PrivateKey: used to spend UTXOs. - PaymentAddress: used to receive UTXOs. - ReadonlyKey: used to decrypt UTXOs. - OTAKey: used to check the owner of UTXOs.
func (*KeySet) GenerateKey ¶
GenerateKey generates key set from seed in byte array.
func (*KeySet) InitFromPrivateKey ¶
func (keySet *KeySet) InitFromPrivateKey(privateKey *PrivateKey) error
InitFromPrivateKey receives private key in PrivateKey type, and re-generates the payment address and other related keys. It returns an Error if private key is invalid.
func (*KeySet) InitFromPrivateKeyByte ¶
InitFromPrivateKeyByte receives private key in bytes array, and re-generates its payment address and other related keys. It returns an Error if the private key is invalid.
type OTAKey ¶
type OTAKey struct {
// contains filtered or unexported fields
}
OTAKey is a wrapped version of a PrivateOTAKey.
func GenerateOTAKey ¶
GenerateOTAKey returns the OTAKey given a PrivateKey.
func (OTAKey) GetOTASecretKey ¶
GetOTASecretKey returns the PrivateOTAKey of an OTAKey.
func (OTAKey) GetPublicSpend ¶
GetPublicSpend returns the PublicKey of an OTAKey.
func (*OTAKey) SetOTASecretKey ¶
SetOTASecretKey sets v as the PrivateOTAKey of an OTAKey.
func (*OTAKey) SetPublicSpend ¶
SetPublicSpend sets v as the PublicKey of an OTAKey.
type PaymentAddress ¶
type PaymentAddress struct { Pk PublicKey // 32 bytes, use to receive coin (CoinV1) Tk TransmissionKey // 32 bytes, use to encrypt pointByte OTAPublic PublicOTAKey //32 bytes, used to receive coin (CoinV2) }
PaymentAddress represents the address of a user. It consists of
- PublicKey: the ID of a user on the blockchain. It is also used to receive UTXOs in a non-private manner (V1).
In Privacy V1, the public key of an UTXO is also the public key of its owner.
- TransmissionKey: to encrypt UTXOs.
- PublicOTAKey: to hide the owner of UTXOs. Only the sender and receiver will be able to know the ownership of the transferred UTXO.
func GeneratePaymentAddress ¶
func GeneratePaymentAddress(privateKey []byte) PaymentAddress
GeneratePaymentAddress returns the PaymentAddress given a PrivateKey.
func (*PaymentAddress) Bytes ¶
func (addr *PaymentAddress) Bytes() []byte
Bytes converts payment address to bytes array
func (PaymentAddress) GetOTAPublicKey ¶
func (addr PaymentAddress) GetOTAPublicKey() *crypto.Point
GetOTAPublicKey returns the PublicOTAKey of a PaymentAddress.
func (PaymentAddress) GetPublicSpend ¶
func (addr PaymentAddress) GetPublicSpend() *crypto.Point
GetPublicSpend returns the PublicKey of a PaymentAddress.
func (PaymentAddress) GetPublicView ¶
func (addr PaymentAddress) GetPublicView() *crypto.Point
GetPublicView returns the TransmissionKey of a PaymentAddress.
func (*PaymentAddress) SetBytes ¶
func (addr *PaymentAddress) SetBytes(bytes []byte) error
SetBytes reverts bytes array to payment address
func (PaymentAddress) String ¶
func (addr PaymentAddress) String() string
String returns a string representation of a PaymentAddress.
type PaymentInfo ¶
type PaymentInfo struct { PaymentAddress PaymentAddress Amount uint64 Message []byte // at most 512 bytes }
PaymentInfo represents the information of a receiver when creating a transaction.
func InitPaymentInfo ¶
func InitPaymentInfo(addr PaymentAddress, amount uint64, message []byte) *PaymentInfo
InitPaymentInfo creates a new PaymentInfo given a PaymentAddress, an amount and a message.
type PrivateKey ¶
type PrivateKey []byte
PrivateKey is a 32-byte long slice which is used to manage an account. A PrivateKey can be used to spend UTXOs, sign transaction, etc.
func GeneratePrivateKey ¶
func GeneratePrivateKey(seed []byte) PrivateKey
GeneratePrivateKey generates a random 32-byte PrivateKey.
type PrivateOTAKey ¶
type PrivateOTAKey []byte
PrivateOTAKey is used to check if an UTXO belong to a user (in Privacy V2).
func GeneratePrivateOTAKey ¶
func GeneratePrivateOTAKey(privateKey []byte) PrivateOTAKey
GeneratePrivateOTAKey returns the PrivateOTAKey given a PrivateKey.
type PublicKey ¶
type PublicKey []byte
PublicKey is the public key corresponding to a PrivateKey, generated by the following formula:
PublicKey = PrivateKey * G[0], where G[0] is the base point for key-related operations. See crypto.PedCom.
func GeneratePublicKey ¶
GeneratePublicKey returns the PublicKey given a PrivateKey.
type PublicOTAKey ¶
type PublicOTAKey []byte
PublicOTAKey is the public key for a PrivateOTAKey. It is used to "encrypt" the owner of UTXOs as well as blind the real asset of UTXOs.
func GeneratePublicOTAKey ¶
func GeneratePublicOTAKey(privateOTAKey PrivateOTAKey) PublicOTAKey
GeneratePublicOTAKey returns the PublicOTAKey given a PrivateOTAKey.
type ReceivingKey ¶
type ReceivingKey []byte
ReceivingKey (a.k.a ReadonlyKey) is used to decrypt UTXOs.
func GenerateReceivingKey ¶
func GenerateReceivingKey(privateKey []byte) ReceivingKey
GenerateReceivingKey returns the ReceivingKey given a PrivateKey.
type TransmissionKey ¶
type TransmissionKey []byte
TransmissionKey is the public key for a ReceivingKey. It is used to encrypt the amount of UTXOs in transactions.
func GenerateTransmissionKey ¶
func GenerateTransmissionKey(receivingKey []byte) TransmissionKey
GenerateTransmissionKey returns the TransmissionKey given a PrivateKey.
type ViewingKey ¶
type ViewingKey struct { Pk PublicKey // 33 bytes, use to receive coin Rk ReceivingKey // 32 bytes, use to decrypt pointByte }
ViewingKey is a wrapped version of a ReceivingKey.
func GenerateViewingKey ¶
func GenerateViewingKey(privateKey []byte) ViewingKey
GenerateViewingKey returns the ViewingKey given a PrivateKey.
func (ViewingKey) GetPrivateView ¶
func (viewKey ViewingKey) GetPrivateView() *crypto.Scalar
GetPrivateView returns the ReceivingKey of a ViewingKey.
func (ViewingKey) GetPublicSpend ¶
func (viewKey ViewingKey) GetPublicSpend() *crypto.Point
GetPublicSpend returns the PublicKey of a ViewingKey.