crypto

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0, UNKNOWN, UNKNOWN not legal advice Imports: 0 Imported by: 0

README

crypto

crypto is the cryptographic package originally adapted for Tendermint's uses.

Importing it

To get the interfaces, import "github.com/gnolang/gno/libs/crypto"

For any specific algorithm, use its specific module e.g. import "github.com/gnolang/gno/libs/crypto/ed25519"

Documentation

Index

Examples

Constants

View Source
const (
	// Bech32AddrPrefix defines the Bech32 prefix of an address
	Bech32AddrPrefix = "g"

	// Bech32PubKeyPrefix defines the Bech32 prefix of a pubkey
	Bech32PubKeyPrefix = "gpub"

	// Atom in https://github.com/satoshilabs/slips/blob/master/slip-0044.md
	CoinType uint32 = 118

	// BIP44Prefix is the parts of the BIP44 HD path that are fixed by
	// what we used during the fundraiser.
	Bip44DefaultPath = "44'/118'/0'/0/0"
)
View Source
const (
	// AddressSize is the size of a pubkey address.
	AddressSize = tmhash.TruncatedSize
)
View Source
const Version = "v1.0.0-rc.0"

Variables

This section is empty.

Functions

func AddressToBech32

func AddressToBech32(addr Address) string

func CRandBytes

func CRandBytes(numBytes int) []byte

This only uses the OS's randomness

func CRandHex

func CRandHex(numDigits int) string

CRandHex returns a hex encoded string that's floor(numDigits/2) * 2 long.

Note: CRandHex(24) gives 96 bits of randomness that are usually strong enough for most purposes.

func CReader

func CReader() io.Reader

Returns a crand.Reader.

func GetFromBech32

func GetFromBech32(bech32str, prefix string) ([]byte, error)

GetFromBech32 decodes a bytestring from a Bech32 encoded string.

func PubKeyToBech32

func PubKeyToBech32(pub PubKey) string

func Sha256

func Sha256(bytes []byte) []byte
Example
package main

import (
	"fmt"

	"github.com/gnolang/gno/tm2/pkg/crypto"
)

func main() {
	sum := crypto.Sha256([]byte("This is Tendermint"))
	fmt.Printf("%x\n", sum)
}
Output:

f91afb642f3d1c87c17eb01aae5cb65c242dfdbe7cf1066cc260f4ce5d33b94e

Types

type Address

type Address [AddressSize]byte

(truncated) hash of some preimage (typically of a pubkey).

func AddressFromBech32

func AddressFromBech32(bech32str string) (Address, error)

func AddressFromBytes

func AddressFromBytes(bz []byte) (ret Address)

func AddressFromID

func AddressFromID(id ID) (addr Address, err error)

func AddressFromPreimage

func AddressFromPreimage(bz []byte) Address

func AddressFromString

func AddressFromString(str string) (addr Address, err error)

func MustAddressFromString

func MustAddressFromString(str string) (addr Address)

func (Address) Bech32

func (addr Address) Bech32() Bech32Address

func (Address) Bytes

func (addr Address) Bytes() []byte

func (Address) Compare

func (addr Address) Compare(other Address) int

func (*Address) DecodeID

func (addr *Address) DecodeID(id ID) error

func (*Address) DecodeString

func (addr *Address) DecodeString(str string) error

func (Address) ID

func (addr Address) ID() ID

func (Address) IsZero

func (addr Address) IsZero() bool

func (Address) MarshalAmino

func (addr Address) MarshalAmino() (string, error)

func (Address) MarshalJSON

func (addr Address) MarshalJSON() ([]byte, error)

func (Address) String

func (addr Address) String() string

func (*Address) UnmarshalAmino

func (addr *Address) UnmarshalAmino(b32str string) (err error)

func (*Address) UnmarshalJSON

func (addr *Address) UnmarshalJSON(b []byte) error

type Bech32Address

type Bech32Address string

func (Bech32Address) String

func (b32 Bech32Address) String() string

type ID

type ID string

The bech32 representation w/ bech32 prefix.

func (ID) IsZero

func (id ID) IsZero() bool

func (ID) String

func (id ID) String() string

func (ID) Validate

func (id ID) Validate() error

type PrivKey

type PrivKey interface {
	// Stable
	Bytes() []byte
	Sign(msg []byte) ([]byte, error)
	PubKey() PubKey
	Equals(PrivKey) bool
}

All operations must be deterministic.

func PrivKeyFromBytes

func PrivKeyFromBytes(privKeyBytes []byte) (privKey PrivKey, err error)

type PubKey

type PubKey interface {
	// Stable
	Address() Address
	Bytes() []byte
	VerifyBytes(msg []byte, sig []byte) bool
	Equals(PubKey) bool
	String() string
}

All operations must be deterministic.

func PubKeyFromBech32

func PubKeyFromBech32(bech32str string) (pubKey PubKey, err error)

func PubKeyFromBytes

func PubKeyFromBytes(pubKeyBytes []byte) (pubKey PubKey, err error)

type Symmetric

type Symmetric interface {
	Keygen() []byte
	Encrypt(plaintext []byte, secret []byte) (ciphertext []byte)
	Decrypt(ciphertext []byte, secret []byte) (plaintext []byte, err error)
}

Jump to

Keyboard shortcuts

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