masacrypto

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeSha256Cid added in v0.6.0

func ComputeSha256Cid(str string) (string, error)

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

func GenerateSelfSignedCert(certPath, keyPath string) error

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.

func Libp2pPubKeyToEthAddress

func Libp2pPubKeyToEthAddress(pubKey crypto.PubKey) (string, error)

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 KeyManagerInstance

func KeyManagerInstance() *KeyManager

KeyManagerInstance returns the singleton instance of KeyManager, initializing it if necessary.

Jump to

Keyboard shortcuts

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