crypto

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: MIT Imports: 22 Imported by: 10

Documentation

Index

Constants

View Source
const (
	AddressLength = 21
	AddressPrefix = "41"
)

Variables

This section is empty.

Functions

func Decode58Check

func Decode58Check(input string) ([]byte, error)

Decode by base58 and check.

func Decrypt

func Decrypt(key, text []byte) ([]byte, error)

func EcdsaSign

func EcdsaSign(ecdsa *ecdsa.PrivateKey, bytes []byte) ([]byte, error)

func Encode58Check

func Encode58Check(input []byte) (string, error)

Encode by base58 and check.

func Encrypt

func Encrypt(key, text []byte) (string, error)

func FromHex

func FromHex(input string) ([]byte, error)

Decode hex string as bytes

func FromPrivKey

func FromPrivKey(privKey ic.PrivKey) (string, error)

func FromPubKey

func FromPubKey(pubKey ic.PubKey) (string, error)

func GenKeyPairs

func GenKeyPairs() (ic.PrivKey, ic.PubKey, error)

func GetPrivKeyFromHexOrBase64

func GetPrivKeyFromHexOrBase64(raw string) (ic.PrivKey, error)

GetPrivKeyFromHexOrBase64 can decode a priv key from either hex or base64 format to satisfy different key storage encoding schemes

func GetPubKeyFromPeerId

func GetPubKeyFromPeerId(pid string) (ic.PubKey, error)

func GetRawFullFromPeerIdPretty

func GetRawFullFromPeerIdPretty(peerid string) ([]byte, error)

func GetTronPubKeyFromIcPubKey

func GetTronPubKeyFromIcPubKey(pubkey ic.PubKey) (*string, error)

func GetTronPubKeyFromPeerIdPretty

func GetTronPubKeyFromPeerIdPretty(peerId string) (*string, error)

func GetTronPubKeyFromPubkey

func GetTronPubKeyFromPubkey(pubkeyS string) (*string, error)

func Hash

func Hash(s []byte) ([]byte, error)

Package goLang sha256 hash algorithm.

func Hex64ToBase64

func Hex64ToBase64(key string) (string, error)

func HexToECDSA

func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)

func Pad

func Pad(src []byte) []byte

pkcs7 padding

func Secp256k1PublicKeyRaw

func Secp256k1PublicKeyRaw(pk ic.PubKey) (res []byte, err error)

Raw returns the bytes of the key

func Sign

func Sign(key ic.PrivKey, channelMessage proto.Message) ([]byte, error)

func ToPrivKey

func ToPrivKey(privKey string) (ic.PrivKey, error)

private key string to ic.PrivKey interface btfs config stores base64 of private key

func ToPrivKeyRaw

func ToPrivKeyRaw(privKey []byte) (ic.PrivKey, error)

Secp256k1 private key string to ic.PrivKey interface

func ToPubKey

func ToPubKey(pubKey string) (ic.PubKey, error)

public key string to ic.PubKey interface

func ToPubKeyRaw

func ToPubKeyRaw(pubKey []byte) (ic.PubKey, error)

public key string to ic.PubKey interface

func TronSign

func TronSign(privKey ic.PrivKey, msg proto.Message) ([]byte, error)

func TronSignRaw

func TronSignRaw(privKey ic.PrivKey, data []byte) ([]byte, error)

func Unpad

func Unpad(src []byte) ([]byte, error)

func Verify

func Verify(key ic.PubKey, channelMessage proto.Message, sig []byte) (bool, error)

Types

type Address

type Address [AddressLength]byte

func AddressLedgerToTron

func AddressLedgerToTron(ledgerAddress []byte) (Address, error)

Get Tron address from ledger address

func BytesToAddress

func BytesToAddress(b []byte) Address

func EcdsaPublicKeyToAddress

func EcdsaPublicKeyToAddress(p ecdsa.PublicKey) (Address, error)

func PublicKeyToAddress

func PublicKeyToAddress(p ecdsa.PublicKey) (Address, error)

ecdsa key to Tron address

func (*Address) Bytes

func (a *Address) Bytes() []byte

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte)

Convert byte to address.

type Keys

type Keys struct {
	Base58Address string
	HexAddress    string
	HexPrivateKey string
	HexPubKey     string
	Base64PubKey  string
}

func FromIcPrivateKey

func FromIcPrivateKey(privKey ic.PrivKey) (*Keys, error)

func FromPrivateKey

func FromPrivateKey(key string) (*Keys, error)

Jump to

Keyboard shortcuts

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