Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeSha256Cid ¶ added in v0.6.0
ComputeSha256Cid calculates the CID (Content Identifier) for a given string.
Parameters:
- str: The input string for which to compute the CID.
Returns:
- string: The computed CID as a string.
- error: An error, if any occurred during the CID computation.
The function uses the multihash package to create a SHA2-256 hash of the input string. It then creates a CID (version 1) from the multihash and returns the CID as a string. If an error occurs during the multihash computation or CID creation, it is returned.
func GenerateSelfSignedCert ¶
GenerateSelfSignedCert generates a self-signed X.509 certificate and private key, saving them to the provided file paths.
It generates a new ECDSA P-256 private key. It sets the certificate fields like validity period, subject, extensions etc. based on best practices. Finally, it encodes the certificate and private key in PEM format and saves them to the provided file paths.
Types ¶
type KeyManager ¶
type KeyManager struct { Libp2pPrivKey crypto.PrivKey // Libp2p private key Libp2pPubKey crypto.PubKey // Libp2p public key EcdsaPrivKey *ecdsa.PrivateKey // ECDSA private key EcdsaPubKey *ecdsa.PublicKey // ECDSA public key HexPrivKey string // Hex-encoded private key HexPubKey string // Hex-encoded public key EthAddress string // Ethereum format address }
KeyManager holds all the cryptographic entities used in the application.
func NewKeyManager ¶ added in v0.8.7
func NewKeyManager(privateKey string, privateKeyFile string) (*KeyManager, error)
NewKeyManager returns an initialized KeyManager. It first checks for a private key set via the PrivateKey config. If not found, it tries to load the key from the PrivateKeyFile. As a last resort, it generates a new key and saves it to the private key file. The private key is loaded into both Libp2p and ECDSA formats for use by different parts of the system. The public key and hex-encoded key representations are also derived.