crypto

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

BTCCoinType is the CoinType for Bitcoin.

View Source
const COSMOSCoinType = types.CoinType_CoinType_COSMOS

COSMOSCoinType is the CoinType for Cosmos.

View Source
const (
	// ChallengeLength - Length of bytes to generate for a challenge
	ChallengeLength = 32
)

DOGECoinType is the CoinType for Dogecoin.

ETHCoinType is the CoinType for Ethereum.

Ed25519KeyType is the key type for ed25519.

FILCoinType is the CoinType for Filecoin.

HNSCoinType is the CoinType for Handshake.

LTCCoinType is the CoinType for Litecoin.

RSAKeyType is the key type for RSA.

SOLCoinType is the CoinType for Solana.

SONRCoinType is the CoinType for Sonr.

Secp256k1KeyType is the key type for secp256k1.

TestCoinType is the CoinType for Testnet.

WebAuthnKeyType is the key type for WebAuthn.

XRPCoinType is the CoinType for XRP.

Variables

View Source
var AllCoinTypes = types.AllCoinTypes

AllCoinTypes is a slice of all CoinTypes.

Functions

func Base58Decode

func Base58Decode(str string) ([]byte, error)

Base58Decode takes a base68 encoded string and returns a byte array.

func Base58Encode

func Base58Encode(bz []byte) string

Base58Encode takes a byte array and returns a base68 encoded string.

func Base64Decode

func Base64Decode(str string) ([]byte, error)

Base64Decode takes a base64 encoded string and returns a byte array.

func Base64Encode

func Base64Encode(bz []byte) string

Base64Encode takes a byte array and returns a base64 encoded string.

func GenerateChallenge

func GenerateChallenge() (challenge protocol.URLEncodedBase64, err error)

GenerateChallenge creates a new challenge that should be signed and returned by the authenticator. The spec recommends using at least 16 bytes with 100 bits of entropy. We use 32 bytes.

func HexDecode

func HexDecode(str string) ([]byte, error)

HexDecode takes a hex encoded string and returns a byte array.

func HexEncode

func HexEncode(bz []byte) string

HexEncode takes a byte array and returns a hex encoded string.

func NewSNRCoins

func NewSNRCoins(amt int) sdk.Coins

NewSNRCoins returns a new sdk.Coins object with the given amount of SNR.

func NewUSNRCoins

func NewUSNRCoins(amt int) sdk.Coins

NewUSNRCoins returns a new sdk.Coins object with the given amount of USNR.

Types

type AccountData

type AccountData = crypto.AccountData

AccountData is the data that is returned by the keygen process. It contains the address, the algorithm used to generate the key pair and the public key.

func NewDefaultAccountData

func NewDefaultAccountData(cointype CoinType, publicKey *PubKey) (*AccountData, error)

NewDefaultAccountData creates a new AccountData with the default values.

type Algo

type Algo string

Algo is the type of algorithm used for key generation.

const (
	// AlgoSecp256k1 is the secp256k1 algorithm.
	AlgoSecp256k1 Algo = "secp256k1"

	// AlgoEd25519 is the ed25519 algorithm.
	AlgoEd25519 Algo = "ed25519"

	// AlgoSr25519 is the sr25519 algorithm.
	AlgoSr25519 Algo = "sr25519"
)

func (Algo) KeyType

func (a Algo) KeyType() KeyType

KeyType returns the KeyType of the algorithm.

type CoinType

type CoinType = types.CoinType

CoinType is a type alias for types.CoinType in pkg/crypto/internal/types.

func CoinTypeFromAddrPrefix

func CoinTypeFromAddrPrefix(str string) CoinType

CoinTypeFromAddrPrefix returns the CoinType from the public key address prefix (btc, eth).

func CoinTypeFromBipPath

func CoinTypeFromBipPath(i uint32) CoinType

CoinTypeFromBipPath returns the CoinType from the BIP Path (0, 60).

func CoinTypeFromDidMethod

func CoinTypeFromDidMethod(str string) CoinType

CoinTypeFromDidMethod returns the CoinType from the DID Method (btc, eth).

func CoinTypeFromName

func CoinTypeFromName(str string) CoinType

CoinTypeFromName returns the CoinType from the Blockchain name (Bitcoin, Ethereum).

func CoinTypeFromTicker

func CoinTypeFromTicker(str string) CoinType

CoinTypeFromTicker returns the CoinType from the tokens Ticker (BTC, ETH).

type EncryptionKey

type EncryptionKey interface {
	// Bytes returns the bytes of the encryption key
	Bytes() []byte

	// Encrypt encrypts the message with the encryption key
	Encrypt(msg []byte) ([]byte, error)

	// Decrypt decrypts the message with the encryption key
	Decrypt(msg []byte) ([]byte, error)
}

EncryptionKey is an interface for encryption keys

type KeyType

type KeyType = types.KeyType

KeyType is a type alias for types.KeyType in pkg/crypto/internal/types.

type PubKey

type PubKey = types.PubKey

PubKey is a type alias for types.PubKey in pkg/crypto/internal/types.

func NewEd25519PubKey

func NewEd25519PubKey(bz []byte) *PubKey

NewEd25519PubKey takes a byte array of raw public key bytes and returns a PubKey.

func NewPubKey

func NewPubKey(bz []byte, kt KeyType) *PubKey

NewPubKey takes a byte array and returns a PubKey

func NewRSAPubKey

func NewRSAPubKey(bz []byte) *PubKey

NewRSAPubKey takes a byte array of raw public key bytes and returns a PubKey.

func NewSecp256k1PubKey

func NewSecp256k1PubKey(pk *secp256k1.PubKey) *PubKey

NewSecp256k1PubKey takes a hex string and returns a PubKey

func NewWebAuthnPubKey

func NewWebAuthnPubKey(bz []byte) *PubKey

NewWebAuthnPubKey takes a byte array of raw public key bytes and returns a PubKey.

func PubKeyFromBytes

func PubKeyFromBytes(bz []byte) (*PubKey, error)

PubKeyFromBytes takes a byte array and returns a PubKey

func PubKeyFromDID

func PubKeyFromDID(did string) (*PubKey, error)

PubKeyFromDID takes a string of a DID, decodes it from base58, unmarshals it into a PubKey, and returns the PubKey

type Secp256k1PubKey

type Secp256k1PubKey = secp256k1.PubKey

Secp256k1PubKey is a type alias for secp256k1.PubKey in pkg/crypto/keys/secp256k1.

Jump to

Keyboard shortcuts

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