Documentation ¶
Index ¶
- Constants
- Variables
- func BytesToPubKey(bz []byte, keytype KeyAlg) (cryptotypes.PubKey, error)
- func CreateDIDKeyByPubKey(pubKey cryptotypes.PubKey) (string, error)
- func CreateDIDKeyIDByPubKey(pubKey cryptotypes.PubKey) (string, error)
- func Decode(bs []byte, label string) (string, error)
- func DerefOrDefault[T any](ptr *T, defaultValue T) T
- func Encode(str string, label string) ([]byte, error)
- func Hash(alg HashAlg, bytes []byte) ([]byte, error)
- func HashAlgNames() []string
- func Indexed[T any, U any](f func(t T) U) func(T, int) U
- func IsNil(t any) bool
- func KeyAlgNames() []string
- func Map[T, M any](s []T, f func(T) M) []M
- func NonZeroOrDefault[T any](v, defaultValue T) T
- func ParseURLMust(s string) *url.URL
- func QueryInterpreter(ctx context.Context, i *prolog.Interpreter, query string, limit sdkmath.Uint) (*types.Answer, error)
- func URLMatches(this *url.URL) func(*url.URL) bool
- func VerifySignature(alg KeyAlg, pubKey []byte, msg, sig []byte) (_ bool, err error)
- func WhitelistBlacklistMatches[T any](whitelist []T, blacklist []T, predicate func(item T) func(b T) bool) func(T) bool
- type BoundedBuffer
- type HashAlg
- type KeyAlg
- type URIComponent
Constants ¶
const ( ED25519PubKeyMultiCodec = 0xed SECP256k1PubKeyMultiCodec = 0xe7 )
Variables ¶
var ErrInvalidCharset = errors.New("invalid charset")
var ErrInvalidHashAlg = fmt.Errorf("not a valid HashAlg, try [%s]", strings.Join(_HashAlgNames, ", "))
var ErrInvalidKeyAlg = fmt.Errorf("not a valid KeyAlg, try [%s]", strings.Join(_KeyAlgNames, ", "))
var ErrInvalidSize = func(size int) error { return fmt.Errorf("invalid buffer size %d", size) }
Functions ¶
func BytesToPubKey ¶
func BytesToPubKey(bz []byte, keytype KeyAlg) (cryptotypes.PubKey, error)
BytesToPubKey converts bytes to a PubKey given a key type. Supported key types: secp256k1, ed25519.
func CreateDIDKeyByPubKey ¶
func CreateDIDKeyByPubKey(pubKey cryptotypes.PubKey) (string, error)
CreateDIDKeyByPubKey creates a did:key ID using the given public key. The multicodec key fingerprint is determined by the key type and complies with the did:key format spec found at: https://w3c-ccg.github.io/did-method-key/#format.
func CreateDIDKeyIDByPubKey ¶
func CreateDIDKeyIDByPubKey(pubKey cryptotypes.PubKey) (string, error)
CreateDIDKeyIDByPubKey creates a DID key ID using the given public key. The function is similar to CreateDIDKeyByPubKey but returns the DID with the key ID as hash fragment. The multicodec key fingerprint is determined by the key type and complies with the did:key format spec found at: https://w3c-ccg.github.io/did-method-key/#format.
func Decode ¶
Decode converts a byte slice from a specified encoding to a string. Decode function is the reverse of encode function.
func DerefOrDefault ¶
func DerefOrDefault[T any](ptr *T, defaultValue T) T
DerefOrDefault returns the value of the pointer if it is not nil, otherwise returns the default value.
func HashAlgNames ¶
func HashAlgNames() []string
HashAlgNames returns a list of possible string values of HashAlg.
func Indexed ¶
Indexed returns a function that applies the given function to the given item and returns the result. It's a convenience function to be used with lo.Map which transforms a predicate function into a mapper function by adding an index argument (which is ignored).
func KeyAlgNames ¶
func KeyAlgNames() []string
KeyAlgNames returns a list of possible string values of KeyAlg.
func Map ¶
func Map[T, M any](s []T, f func(T) M) []M
Map applies the given function to each element of the given slice and returns a new slice with the results.
func NonZeroOrDefault ¶
func NonZeroOrDefault[T any](v, defaultValue T) T
NonZeroOrDefault returns the value of the argument if it is not nil and not zero, otherwise returns the default value.
func ParseURLMust ¶
ParseURLMust parses the given url and panics if it fails. You have been warned.
func QueryInterpreter ¶
func QueryInterpreter( ctx context.Context, i *prolog.Interpreter, query string, limit sdkmath.Uint, ) (*types.Answer, error)
QueryInterpreter interprets a query and returns the solutions up to the given limit.
func URLMatches ¶
URLMatches is a function that returns a function that matches the given url against the given other item.
The function matches the components of the given url against the components of the given other url. If the component of the given other url is empty, it is considered to match the component of the given url. For example:
- URLMatches("http://example.com/foo")("http://example.com/foo") -> true
- URLMatches("http://example.com/foo")("http://example.com/foo?bar=baz") -> false
- URLMatches("tel:123456789")("tel:") -> true
The function is curried, and is a binary relation that is reflexive, associative (but not commutative).
func VerifySignature ¶
VerifySignature verifies the signature of the given message with the given public key using the given algorithm.
func WhitelistBlacklistMatches ¶
func WhitelistBlacklistMatches[T any](whitelist []T, blacklist []T, predicate func(item T) func(b T) bool) func(T) bool
WhitelistBlacklistMatches returns a function that matches the given item according to the given whitelist and blacklist returning true if the item matches the whitelist and does not match the blacklist, and false otherwise. Note that if the whitelist is empty, the item is considered to match the whitelist.
Types ¶
type BoundedBuffer ¶
type BoundedBuffer struct {
// contains filtered or unexported fields
}
BoundedBuffer is a fixed size buffer that overwrites older data when the buffer is full.
func NewBoundedBuffer ¶
func NewBoundedBuffer(size int) (*BoundedBuffer, error)
NewBoundedBuffer creates a new BoundedBuffer with the given fixed size. If size is 0, the buffer will be disabled.
func NewBoundedBufferMust ¶
func NewBoundedBufferMust(size int) *BoundedBuffer
NewBoundedBufferMust is like NewBoundedBuffer but panics if an error occurs.
func (*BoundedBuffer) String ¶
func (b *BoundedBuffer) String() string
String returns the contents of the buffer as a string.
type HashAlg ¶
type HashAlg int
HashAlg is the type of hash algorithm supported by the crypto util functions. ENUM(md5,sha256,sha512).
func ParseHashAlg ¶
ParseHashAlg attempts to convert a string to a HashAlg.
type KeyAlg ¶
type KeyAlg int
KeyAlg is the type of key algorithm supported by the crypto util functions. ENUM(secp256k1,secp256r1,ed25519).
func ParseKeyAlg ¶
ParseKeyAlg attempts to convert a string to a KeyAlg.
type URIComponent ¶
type URIComponent int
const ( PathComponent URIComponent = iota SegmentComponent QueryValueComponent FragmentComponent )
func (URIComponent) Escape ¶
func (c URIComponent) Escape(v string) string
Escape return the given input string by adding percent encoding depending on the current component where it's supposed to be put. This is a re-implementation of native url.escape. See shouldEscape() comment's for more details.