nodekey

package module
v0.0.0-...-b5ab8ef Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2022 License: Apache-2.0 Imports: 26 Imported by: 1

README

chain5j-nodekey

简介

chain5j-nodekey chain5j链负责节点私钥签名区块。

功能

证书

chain5j-nodekey 的源码允许用户在遵循 Apache 2.0 开源证书 规则的前提下使用。

版权

Copyright@2022 chain5j

chain5j

Documentation

Overview

Package nodekey

@author: xwc1125

Package nodekey

@author: xwc1125

Package nodekey

@author: xwc1125

Package nodekey

@author: xwc1125

Package nodekey

@author: xwc1125

Package nodekey

@author: xwc1125

Index

Constants

View Source
const (
	FileType_Hex    = "hex"
	FileType_Base64 = "base64"
	FileType_Pem    = "pem"
	FileType_P12    = "p12"
)

Variables

View Source
var (
	ErrFileType = errors.New("unsupported the fileType")
)

Functions

func IDFromPrivateKey

func IDFromPrivateKey(sk protocol.PrivKey) (models.NodeID, error)

IDFromPrivateKey 通过私钥获取PeerID

func IDFromPublicKey

func IDFromPublicKey(pk protocol.PubKey) (models.NodeID, error)

IDFromPublicKey 根据公钥生成PeerID

func IdFromPub

func IdFromPub(pub crypto.PublicKey) (models.NodeID, error)

IdFromPub 将ecdsa publicKey转换为NodeId

func MarshalPrivateKey

func MarshalPrivateKey(prvKey crypto.PrivateKey) (*pcrypto.JsonKey, error)

func MarshalPrivateKeyX509

func MarshalPrivateKeyX509(prvKey crypto.PrivateKey) (*pcrypto.JsonKey, error)

func MarshalPublicKey

func MarshalPublicKey(ePub crypto.PublicKey) (*pcrypto.JsonKey, error)

func MarshalPublicKeyX509

func MarshalPublicKeyX509(ePub crypto.PublicKey) (*pcrypto.JsonKey, error)

func NewNodeKey

func NewNodeKey(rootCtx context.Context, opts ...option) (protocol.NodeKey, error)

NewNodeKey 创建新的NodeKey

func RecoverId

func RecoverId(data []byte, signResult *signature.SignResult) (models.NodeID, error)

RecoverId 从签名中恢复出ID

func SavePrivateKey

func SavePrivateKey(prvKey *PrivateKey, fileType FileType, prvKeyFile string, pubKeyFile string, pwd string) error

SavePrivateKey 保存节点私钥到nodekey文件

func SaveToPemFile

func SaveToPemFile(prvKey *PrivateKey, prvKeyFile string, pubKeyFile string, pwd string) error

func Sign

func Sign(data []byte, prv crypto.PrivateKey) (sig *signature.SignResult, err error)

Sign 签名数据[节点之间的签名]

func Verify

func Verify(data []byte, signResult *signature.SignResult) (bool, error)

Verify 验证签名内容 sigBytes 是signResult的bytes值

func WithConfig

func WithConfig(config protocol.Config) option

Types

type FileType

type FileType string

type PrivateKey

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

PrivateKey 私钥,实现p2p的私钥接口

func GenerateKeyPair

func GenerateKeyPair(cryptoType pcrypto.CryptoType) (*PrivateKey, error)

GenerateKeyPair 生成p2p对应的公私钥

func LoadPrivateKey

func LoadPrivateKey(fileType FileType, prvKeyFile string, pubKeyFile string, pwd string, args ...string) (*PrivateKey, error)

LoadPrivateKey 从指定路径下加载nodekey文件

func NewPrivateKey

func NewPrivateKey(prv crypto.PrivateKey) (*PrivateKey, error)

NewPrivateKey 根据原生私钥创建一个自有私钥

func ParsePrivateKeyPem

func ParsePrivateKeyPem(keyPemBytes, certPemBytes []byte, pwd []byte) (privateKey *PrivateKey, err error)

ParsePrivateKeyPem parse key pem to privateKey

func ToPrivateKey

func ToPrivateKey(prvKey crypto.PrivateKey) (*PrivateKey, error)

ToPrivateKey 将原生的PrivateKey转换为protocol.PrivateKey

func UnmarshalPrivateKey

func UnmarshalPrivateKey(jsonPrvData []byte) (*PrivateKey, error)

func (*PrivateKey) Equals

func (p *PrivateKey) Equals(key protocol.Key) bool

func (*PrivateKey) GetPublic

func (p *PrivateKey) GetPublic() protocol.PubKey

GetPublic 获取public

func (*PrivateKey) Hash

func (p *PrivateKey) Hash() func() hash.Hash

func (*PrivateKey) ID

func (p *PrivateKey) ID() (models.NodeID, error)

ID 返回nodeId

func (*PrivateKey) Marshal

func (p *PrivateKey) Marshal() ([]byte, error)

func (*PrivateKey) MarshalJSON

func (p *PrivateKey) MarshalJSON() ([]byte, error)

func (*PrivateKey) Raw

func (p *PrivateKey) Raw() ([]byte, error)

Raw x509格式,否则libp2p会报错

func (*PrivateKey) Sign

func (p *PrivateKey) Sign(data []byte) (*signature.SignResult, error)

Sign 签名data

func (*PrivateKey) Type

func (p *PrivateKey) Type() protocol.KeyType

func (*PrivateKey) Unmarshal

func (p *PrivateKey) Unmarshal(input []byte) error

func (*PrivateKey) UnmarshalJSON

func (p *PrivateKey) UnmarshalJSON(bytes []byte) error

type PublicKey

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

PublicKey 公钥,实现p2p的公钥接口

func LoadPublicKey

func LoadPublicKey(pubFile string) (*PublicKey, error)

func LoadPublicKeyFromBytes

func LoadPublicKeyFromBytes(pubBytes []byte) (*PublicKey, error)

func NewPublicKey

func NewPublicKey(pub crypto.PublicKey) (*PublicKey, error)

NewPublicKey 原生公钥转自有公钥

func ParsePublicKeyPem

func ParsePublicKeyPem(keyPemBytes []byte) (*PublicKey, error)

ParsePublicKeyPem parse key pem to publicKey

func ToPublicKey

func ToPublicKey(pubKey crypto.PublicKey) (*PublicKey, error)

ToPublicKey 将原生的PublicKey转换为protocol.PublicKey

func UnmarshalPublicKey

func UnmarshalPublicKey(jsonKeyBytes []byte) (*PublicKey, error)

func (*PublicKey) Equals

func (ePub *PublicKey) Equals(key protocol.Key) bool

func (*PublicKey) Hash

func (ePub *PublicKey) Hash() func() hash.Hash

func (*PublicKey) Marshal

func (ePub *PublicKey) Marshal() ([]byte, error)

func (*PublicKey) Raw

func (ePub *PublicKey) Raw() ([]byte, error)

Raw x509格式,否则libp2p会报错

func (*PublicKey) Type

func (ePub *PublicKey) Type() protocol.KeyType

func (*PublicKey) Unmarshal

func (ePub *PublicKey) Unmarshal(input []byte) error

func (*PublicKey) Verify

func (ePub *PublicKey) Verify(data []byte, signResult *signature.SignResult) (bool, error)

Verify 验证签名

Jump to

Keyboard shortcuts

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