Documentation
¶
Overview ¶
Package utils common utils
Index ¶
- Constants
- Variables
- func BytesToI64(b []byte) (int64, error)
- func BytesToU64(b []byte) (uint64, error)
- func CheckProposalRequestResp(resp *common.TxResponse, needContractResult bool) error
- func CreateEthAddress(pub ecdsa.PublicKey) ([]byte, error)
- func DecryptHibeTx(localId string, hibeParams []byte, hibePrvKey []byte, tx *common.Transaction, ...) ([]byte, error)
- func Exists(path string) bool
- func F(h *[8]uint64, m [16]uint64, c [2]uint64, f bool, rounds uint32)
- func GenerateECDSAKey() (*ecdsa.PrivateKey, error)
- func GetCertificateId(certPEM []byte, hashType string) ([]byte, error)
- func GetCertificateIdFromDER(certDER []byte, hashType string) ([]byte, error)
- func GetNanoByTimestampTxId(timestampTxId string) (nano int64, err error)
- func GetRandTxId() string
- func GetTimestampTxId() string
- func GetTimestampTxIdByNano(nano int64) string
- func I64ToBytes(i int64) []byte
- func IsArchived(txStatusCode common.TxStatusCode) bool
- func IsArchivedString(txStatusCode string) bool
- func MakeEndorser(orgId string, hashType crypto.HashType, memberType accesscontrol.MemberType, ...) (*common.EndorsementEntry, error)
- func MakeEndorserWithPath(keyFilePath, crtFilePath string, payload *common.Payload) (*common.EndorsementEntry, error)
- func MakeEndorserWithPathAndCSP(keyFilePath, crtFilePath string, p11Handle interface{}, kmsEnabled bool, ...) (*common.EndorsementEntry, error)
- func MakeEndorserWithPem(keyPem, certPem []byte, payload *common.Payload) (*common.EndorsementEntry, error)
- func MakePkEndorserWithPath(keyFilePath string, hashType crypto.HashType, orgId string, ...) (*common.EndorsementEntry, error)
- func MakePkEndorserWithPem(keyPem []byte, hashType crypto.HashType, orgId string, payload *common.Payload) (*common.EndorsementEntry, error)
- func MarshalECDSAPrivateKey(priv *ecdsa.PrivateKey) ([]byte, error)
- func NewEndorser(orgId string, certPem []byte, sig []byte) *common.EndorsementEntry
- func NewEndorserWithMemberType(orgId string, memberInfo []byte, memberType accesscontrol.MemberType, ...) *common.EndorsementEntry
- func NewPayload(opts ...PayloadOption) *commonPb.Payload
- func NewPkEndorser(orgId string, pk []byte, sig []byte) *common.EndorsementEntry
- func ParseCert(crtPEM []byte) (*bcx509.Certificate, error)
- func ParseECDSAPrivateKey(buf []byte) (*ecdsa.PrivateKey, error)
- func ReadHibeParamsWithFilePath(hibeParamsFilePath string) ([]byte, error)
- func ReadHibePrvKeysWithFilePath(hibePrvKeyFilePath string) ([]byte, error)
- func Sign(priv *ecdsa.PrivateKey, hash []byte) ([]byte, error)
- func SignPayload(privateKey crypto.PrivateKey, cert *bcx509.Certificate, ...) ([]byte, error)
- func SignPayloadBytes(privateKey crypto.PrivateKey, cert *bcx509.Certificate, payloadBytes []byte) ([]byte, error)
- func SignPayloadBytesWithHashType(privateKey crypto.PrivateKey, hashType crypto.HashType, payloadBytes []byte) ([]byte, error)
- func SignPayloadWithHashType(privateKey crypto.PrivateKey, hashType crypto.HashType, ...) ([]byte, error)
- func SignPayloadWithPath(keyFilePath, crtFilePath string, payload *common.Payload) ([]byte, error)
- func SignPayloadWithPkPath(keyFilePath, hashType string, payload *common.Payload) ([]byte, error)
- func U64ToBytes(i uint64) []byte
- type BigInteger
- type ChainClientConfigModel
- type Logger
- type PayloadOption
- func AddParameter(parameter *commonPb.KeyValuePair) PayloadOption
- func WithChainId(chainId string) PayloadOption
- func WithContractName(contractName string) PayloadOption
- func WithExpirationTime(expirationTime int64) PayloadOption
- func WithLimit(limit *commonPb.Limit) PayloadOption
- func WithMethod(method string) PayloadOption
- func WithParameters(parameters []*commonPb.KeyValuePair) PayloadOption
- func WithSequence(sequence uint64) PayloadOption
- func WithTimestamp(timestamp int64) PayloadOption
- func WithTxId(txId string) PayloadOption
- func WithTxType(txType commonPb.TxType) PayloadOption
- type TlsConfig
Constants ¶
const ( // SUCCESS ContractResult success code SUCCESS uint32 = 0 // Separator chainmker hex ca Separator = byte(202) )
const ( // HibeMsgKey key HibeMsgKey = "hibe_msg" // HibeMsgIdKey key HibeMsgIdKey = "tx_id" // HibeMsgCipherTextKey key HibeMsgCipherTextKey = "CT" // HibeParamsKey key HibeParamsKey = "org_id" // HibeParamsValueKey key HibeParamsValueKey = "params" )
hibe msg's Keys
const ( // KeyBlockContractWithRWSet key KeyBlockContractWithRWSet = "withRWSet" // KeyBlockContractBlockHash key KeyBlockContractBlockHash = "blockHash" // KeyBlockContractBlockHeight key KeyBlockContractBlockHeight = "blockHeight" // KeyBlockContractTxId key KeyBlockContractTxId = "txId" // KeyBlockContractTruncateValueLen key KeyBlockContractTruncateValueLen = "truncateValueLen" // KeyBlockContractTruncateModel key KeyBlockContractTruncateModel = "truncateModel" // KeyChainConfigContractRoot key KeyChainConfigContractRoot = "root" // KeyChainConfigContractOrgId key KeyChainConfigContractOrgId = "org_id" // KeyChainConfigAddrType key KeyChainConfigAddrType = "addr_type" // KeyChainConfigContractNodeId key KeyChainConfigContractNodeId = "node_id" // KeyChainConfigContractNewNodeId key KeyChainConfigContractNewNodeId = "new_node_id" // KeyChainConfigContractNodeIds key KeyChainConfigContractNodeIds = "node_ids" // KeyChainConfigContractBlockHeight key KeyChainConfigContractBlockHeight = "block_height" // KeyChainConfigContractTrustMemberOrgId key KeyChainConfigContractTrustMemberOrgId = "org_id" // KeyChainConfigContractTrustMemberInfo key KeyChainConfigContractTrustMemberInfo = "member_info" // KeyChainConfigContractTrustMemberNodeId key KeyChainConfigContractTrustMemberNodeId = "node_id" // KeyChainConfigContractTrustMemberRole key KeyChainConfigContractTrustMemberRole = "role" // KeyTxSchedulerTimeout key KeyTxSchedulerTimeout = "tx_scheduler_timeout" // KeyTxSchedulerValidateTimeout key KeyTxSchedulerValidateTimeout = "tx_scheduler_validate_timeout" // KeyEnableOptimizeChargeGas key KeyEnableOptimizeChargeGas = "enable_optimize_charge_gas" // KeyTxTimeOut key KeyTxTimeOut = "tx_timeout" // KeyBlockTxCapacity key KeyBlockTxCapacity = "block_tx_capacity" // KeyBlockSize key KeyBlockSize = "block_size" // KeyBlockInterval key KeyBlockInterval = "block_interval" // KeyTxParamterSize key KeyTxParamterSize = "tx_parameter_size" // KeyBlockTimeOut key KeyBlockTimeOut = "block_timeout" // KeyMinSelfDelegation key KeyMinSelfDelegation = "min_self_delegation" // KeyEpochValidatorNumber key KeyEpochValidatorNumber = "epoch_validator_number" // KeyEpochBlockNumber key KeyEpochBlockNumber = "epoch_block_number" // KeyDistributionPerBlock key KeyDistributionPerBlock = "distribution_per_block" // KeySlashingPerBlock key KeySlashingPerBlock = "slashing_per_block" // KeyDistributionFromSlashing key KeyDistributionFromSlashing = "distribution_from_slashing" // KeyGasExchangeRate key KeyGasExchangeRate = "gas_exchange_rate" // KeyAddress key KeyAddress = "address" // KeyAmount key KeyAmount = "amount" // KeyOwner key KeyOwner = "owner" // KeyTo key KeyTo = "to" // KeyFrom key KeyFrom = "from" // KeyValue key KeyValue = "value" // KeyCertHashes key KeyCertHashes = "cert_hashes" // KeyCerts key KeyCerts = "certs" // KeyCertCrl key KeyCertCrl = "cert_crl" // KeyOrderId key KeyOrderId = "order_id" // KeyPrivateDir key KeyPrivateDir = "private_dir" // KeyContractName key KeyContractName = "contract_name" // KeyCodeHash key KeyCodeHash = "code_hash" // KeyResult key KeyResult = "result" // KeyCodeHeader key KeyCodeHeader = "code_header" // KeyVersion key KeyVersion = "version" // KeyIsDeploy key KeyIsDeploy = "is_deploy" // KeyRWSet key KeyRWSet = "rw_set" // KeyEvents key KeyEvents = "events" // KeyReportHash key KeyReportHash = "report_hash" // KeySign key KeySign = "sign" // KeyKey key KeyKey = "key" // KeyPrefix key KeyPrefix = "prefix" // KeyPayload key KeyPayload = "payload" // KeyOrgIds key KeyOrgIds = "org_ids" // KeySignPairs key KeySignPairs = "sign_pairs" // KeyCaCert key KeyCaCert = "ca_cert" // KeyEnclaveId key KeyEnclaveId = "enclave_id" // KeyReport key KeyReport = "report" // KeyProof key KeyProof = "proof" // KeyDeployReq key KeyDeployReq = "deploy_req" // KeyPrivateReq key KeyPrivateReq = "private_req" // KeyPubkey key KeyPubkey = "pubkey" // KeyPubkeyRole key KeyPubkeyRole = "role" // KeyPubkeyOrgId key KeyPubkeyOrgId = "org_id" // KeyGasAddressKey key KeyGasAddressKey = "address_key" // KeyGasPublicKey key KeyGasPublicKey = "public_key" // KeyGasBatchRecharge key KeyGasBatchRecharge = "batch_recharge" // KeyGasBalancePublicKey key KeyGasBalancePublicKey = "balance_public_key" // KeyGasChargePublicKey key KeyGasChargePublicKey = "charge_public_key" // KeyGasChargeGasAmount key KeyGasChargeGasAmount = "charge_gas_amount" // KeyGasFrozenPublicKey key KeyGasFrozenPublicKey = "frozen_public_key" // KeySetInvokeBaseGas key KeySetInvokeBaseGas = "set_invoke_base_gas" // KeySetInvokeGasPrice key KeySetInvokeGasPrice = "set_invoke_gas_price" // KeySetInstallBaseGas key KeySetInstallBaseGas = "set_install_base_gas" // KeySetInstallGasPrice key KeySetInstallGasPrice = "set_install_gas_price" // KeyMultiSignEnableManualRun key KeyMultiSignEnableManualRun = "multi_sign_enable_manual_run" // KeyVMType key KeyVMType = "vm_type" // ValueVMTypeDockerJava value ValueVMTypeDockerJava = "dockerjava" )
nolint
const ( // MysqlDBNamePrefix archive config: mysql db name prefix MysqlDBNamePrefix = "cm_archived_chain" // MysqlTableNamePrefix archive config: mysql table name prefix MysqlTableNamePrefix = "t_block_info" // RowsPerBlockInfoTable archive config: count of rows per block_info table RowsPerBlockInfoTable = 100000 )
nolint
const DecBase = 10
DecBase 10
Variables ¶
var IV = [8]uint64{
0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,
0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179,
}
IV is an initialization vector for BLAKE2b
Functions ¶
func CheckProposalRequestResp ¶
func CheckProposalRequestResp(resp *common.TxResponse, needContractResult bool) error
CheckProposalRequestResp check tx response is ok or not
func CreateEthAddress ¶
CreateEthAddress create k1 curve eth address args:
- ecdsa.PublicKey
returns:
- []byte
- error
func DecryptHibeTx ¶
func DecryptHibeTx(localId string, hibeParams []byte, hibePrvKey []byte, tx *common.Transaction, keyType crypto.KeyType) ([]byte, error)
DecryptHibeTx Decrypt Hibe Tx args:
- string
- []byte
- []byte
- *common.Transaction
- crypto.KeyType
returns:
- []byte
- error
func Exists ¶
Exists returns a boolean indicating whether the error is known to report that a file or directory already exists.
func F ¶
F is a compression function for BLAKE2b. It takes as an argument the state vector `h`, message block vector `m`, offset counter `t`, final block indicator flag `f`, and number of rounds `rounds`. The state vector provided as the first parameter is modified by the function. nolint
func GenerateECDSAKey ¶
func GenerateECDSAKey() (*ecdsa.PrivateKey, error)
GenerateECDSAKey generates a new key based on the secp256k1 elliptic curve. returns:
- *ecdsa.PrivateKey
- error
func GetCertificateId ¶
GetCertificateId get cert id from cert pem
func GetCertificateIdFromDER ¶
GetCertificateIdFromDER get cert id from cert der
func GetNanoByTimestampTxId ¶
GetNanoByTimestampTxId validate and parse 160 ... 223 22
func GetTimestampTxId ¶
func GetTimestampTxId() string
GetTimestampTxId by current time, see: GetTimestampTxIdByNano eg: 687dca1d9c4fdf1652fdfc072182654f53622c496aa94c05b47d34263cd99ec9
func GetTimestampTxIdByNano ¶
GetTimestampTxIdByNano nanosecond
func IsArchived ¶
func IsArchived(txStatusCode common.TxStatusCode) bool
IsArchived returns a boolean indicating whether is archived by txStatusCode in common.TxStatusCode
func IsArchivedString ¶
IsArchivedString returns a boolean indicating whether is archived by txStatusCode in string
func MakeEndorser ¶
func MakeEndorser(orgId string, hashType crypto.HashType, memberType accesscontrol.MemberType, keyPem, memberInfo []byte, payload *common.Payload) (*common.EndorsementEntry, error)
MakeEndorser returns *common.EndorsementEntry args:
- string
- crypto.HashType
- accesscontrol.MemberType
- []byte
- []byte
- *common.Payload
returns:
- *common.EndorsementEntry
- error
func MakeEndorserWithPath ¶
func MakeEndorserWithPath(keyFilePath, crtFilePath string, payload *common.Payload) (*common.EndorsementEntry, error)
MakeEndorserWithPath make endorser with key/cert file path args:
- string
- string
- *common.Payload
returns:
- *common.EndorsementEntry
- error
func MakeEndorserWithPathAndCSP ¶
func MakeEndorserWithPathAndCSP(keyFilePath, crtFilePath string, p11Handle interface{}, kmsEnabled bool, payload *common.Payload) (*common.EndorsementEntry, error)
MakeEndorserWithPathAndCSP used to sign payload by kms or hsm args:
- string
- string
- interface{}
- bool
- *common.Payload
returns:
- *common.EndorsementEntry
- error
func MakeEndorserWithPem ¶
func MakeEndorserWithPem(keyPem, certPem []byte, payload *common.Payload) (*common.EndorsementEntry, error)
MakeEndorserWithPem make endorser with pem Deprecated: This function will be deleted when appropriate. Please use MakeEndorser args:
- []byte
- []byte
- *common.Payload
returns:
- *common.EndorsementEntry
- error
func MakePkEndorserWithPath ¶
func MakePkEndorserWithPath(keyFilePath string, hashType crypto.HashType, orgId string, payload *common.Payload) (*common.EndorsementEntry, error)
MakePkEndorserWithPath make public mode endorser with key file path args:
- string
- crypto.HashType
- string
- *common.Payload
returns:
- *common.EndorsementEntry
- error
func MakePkEndorserWithPem ¶
func MakePkEndorserWithPem(keyPem []byte, hashType crypto.HashType, orgId string, payload *common.Payload) (*common.EndorsementEntry, error)
MakePkEndorserWithPem make public mode endorser with pem Deprecated: This function will be deleted when appropriate. Please use MakeEndorser args:
- []byte
- crypto.HashType
- string
- *common.Payload
returns:
- *common.EndorsementEntry
- error
func MarshalECDSAPrivateKey ¶
func MarshalECDSAPrivateKey(priv *ecdsa.PrivateKey) ([]byte, error)
MarshalECDSAPrivateKey serializes the private key's D value to a []byte args:
- *ecdsa.PrivateKey
returns:
- []byte
- error
func NewEndorser ¶
func NewEndorser(orgId string, certPem []byte, sig []byte) *common.EndorsementEntry
NewEndorser returns *common.EndorsementEntry Deprecated: This function will be deleted when appropriate. Please use NewEndorserWithMemberType args:
- string
- []byte
- []byte
returns:
- *common.EndorsementEntry
func NewEndorserWithMemberType ¶
func NewEndorserWithMemberType(orgId string, memberInfo []byte, memberType accesscontrol.MemberType, sig []byte) *common.EndorsementEntry
NewEndorserWithMemberType new endorser with member type args:
- string
- []byte
- accesscontrol.MemberType
- []byte
returns:
- *common.EndorsementEntry
func NewPayload ¶
func NewPayload(opts ...PayloadOption) *commonPb.Payload
NewPayload new payload args:
- ...PayloadOption
returns:
- *commonPb.Payload
func NewPkEndorser ¶
func NewPkEndorser(orgId string, pk []byte, sig []byte) *common.EndorsementEntry
NewPkEndorser returns *common.EndorsementEntry args:
- string
- []byte
- []byte
returns:
- *common.EndorsementEntry
func ParseCert ¶
func ParseCert(crtPEM []byte) (*bcx509.Certificate, error)
ParseCert parse cert pem to *bcx509.Certificate
func ParseECDSAPrivateKey ¶
func ParseECDSAPrivateKey(buf []byte) (*ecdsa.PrivateKey, error)
ParseECDSAPrivateKey parse ECDSA private key args:
- []byte
returns:
- *ecdsa.PrivateKey
- error
func ReadHibeParamsWithFilePath ¶
ReadHibeParamsWithFilePath Returns the serialized byte array of hibeParams args:
- string
returns:
- []byte
- error
func ReadHibePrvKeysWithFilePath ¶
ReadHibePrvKeysWithFilePath Returns the serialized byte array of hibePrvKey args:
- string
returns:
- []byte
- error
func Sign ¶
func Sign(priv *ecdsa.PrivateKey, hash []byte) ([]byte, error)
Sign produces a compact signature of the data in hash with the given private key on the secp256k1 curve. args:
- *ecdsa.PrivateKey
- []byte
returns:
- []byte
- error
func SignPayload ¶
func SignPayload(privateKey crypto.PrivateKey, cert *bcx509.Certificate, payload *common.Payload) ([]byte, error)
SignPayload sign payload Deprecated: This function will be deleted when appropriate. Please use SignPayloadWithHashType args:
- crypto.PrivateKey
- *bcx509.Certificate
- *common.Payload
returns:
- []byte
- error
func SignPayloadBytes ¶
func SignPayloadBytes(privateKey crypto.PrivateKey, cert *bcx509.Certificate, payloadBytes []byte) ([]byte, error)
SignPayloadBytes sign payload bytes Deprecated: This function will be deleted when appropriate. Please use SignPayloadBytesWithHashType args:
- crypto.PrivateKey
- *bcx509.Certificate
- []byte
returns:
- []byte
- error
func SignPayloadBytesWithHashType ¶
func SignPayloadBytesWithHashType(privateKey crypto.PrivateKey, hashType crypto.HashType, payloadBytes []byte) ([]byte, error)
SignPayloadBytesWithHashType sign payload bytes with specified hash type args:
- crypto.PrivateKey
- crypto.HashType
- []byte
returns:
- []byte
- error
func SignPayloadWithHashType ¶
func SignPayloadWithHashType(privateKey crypto.PrivateKey, hashType crypto.HashType, payload *common.Payload) ([]byte, error)
SignPayloadWithHashType sign payload with specified hash type args:
- crypto.PrivateKey
- crypto.HashType
- *common.Payload
returns:
- []byte
- error
func SignPayloadWithPath ¶
SignPayloadWithPath sign payload with specified key/cert file path args:
- string
- string
- *common.Payload
returns:
- []byte
- error
func SignPayloadWithPkPath ¶
SignPayloadWithPkPath sign payload with specified key file path args:
- string
- string
- *common.Payload
returns:
- []byte
- error
Types ¶
type BigInteger ¶
BigInteger wrapper for big.Int
func NewZeroBigInteger ¶
func NewZeroBigInteger() *BigInteger
NewZeroBigInteger create a BigInteger of zero
func (*BigInteger) Cmp ¶
func (x *BigInteger) Cmp(y *BigInteger) int
Cmp compares x and y and returns:
-1 if x < y 0 if x == y +1 if x > y
type ChainClientConfigModel ¶
type ChainClientConfigModel struct {
ChainClientConfig chainClientConfigModel `mapstructure:"chain_client"`
}
ChainClientConfigModel define ChainClientConfigModel
func InitConfig ¶
func InitConfig(confPath string) (*ChainClientConfigModel, error)
InitConfig init config from config file path args:
- confPath, sdk config file path
returns:
- *ChainClientConfigModel
- error
type Logger ¶
type Logger interface { Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) Warnf(format string, args ...interface{}) Errorf(format string, args ...interface{}) Debug(args ...interface{}) Info(args ...interface{}) Warn(args ...interface{}) Error(args ...interface{}) }
Logger define log interface
type PayloadOption ¶
PayloadOption define payload option func
func AddParameter ¶
func AddParameter(parameter *commonPb.KeyValuePair) PayloadOption
AddParameter add one Parameter of payload args:
- []*commonPb.KeyValuePair
returns:
- PayloadOption
func WithChainId ¶
func WithChainId(chainId string) PayloadOption
WithChainId set chainId of payload args:
- string
returns:
- PayloadOption
func WithContractName ¶
func WithContractName(contractName string) PayloadOption
WithContractName set ContractName of payload args:
- string
returns:
- PayloadOption
func WithExpirationTime ¶
func WithExpirationTime(expirationTime int64) PayloadOption
WithExpirationTime set ExpirationTime of payload args:
- int64
returns:
- PayloadOption
func WithLimit ¶
func WithLimit(limit *commonPb.Limit) PayloadOption
WithLimit set Limit of payload args:
- *commonPb.Limit
returns:
- PayloadOption
func WithMethod ¶
func WithMethod(method string) PayloadOption
WithMethod set Method of payload args:
- string
returns:
- PayloadOption
func WithParameters ¶
func WithParameters(parameters []*commonPb.KeyValuePair) PayloadOption
WithParameters set Parameters of payload args:
- []*commonPb.KeyValuePair
returns:
- PayloadOption
func WithSequence ¶
func WithSequence(sequence uint64) PayloadOption
WithSequence set Sequence of payload args:
- uint64
returns:
- PayloadOption
func WithTimestamp ¶
func WithTimestamp(timestamp int64) PayloadOption
WithTimestamp set Timestamp of payload args:
- int64
returns:
- PayloadOption
func WithTxId ¶
func WithTxId(txId string) PayloadOption
WithTxId set TxId of payload args:
- string
returns:
- PayloadOption
func WithTxType ¶
func WithTxType(txType commonPb.TxType) PayloadOption
WithTxType set TxType of payload args:
- commonPb.TxType
returns:
- PayloadOption