utils

package
v1.0.0-develop.10 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: Apache-2.0 Imports: 19 Imported by: 3

Documentation

Index

Constants

View Source
const (
	IndyIdLength = 16
)
View Source
const StandardUuidLength = 36

Variables

View Source
var (
	SplitDIDRegexp, _     = regexp.Compile(`^did:([^:]+?)(:([^:]+?))?:([^:]+)$`)
	DidNamespaceRegexp, _ = regexp.Compile(`^[a-zA-Z0-9]*$`)
)
View Source
var (
	DIDPathAbemptyRegexp, _ = regexp.Compile(`^([/a-zA-Z0-9\-\.\_\~\!\$\&\'\(\)\*\+\,\;\=\:\@]*|(%[0-9A-Fa-f]{2})*)*$`)
	DIDQueryRegexp, _       = regexp.Compile(`^([/a-zA-Z0-9\-\.\_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\/\?]*|(%[0-9A-Fa-f]{2})*)*$`)
	DIDFragmentRegexp, _    = regexp.Compile(`^([/a-zA-Z0-9\-\.\_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\/\?]*|(%[0-9A-Fa-f]{2})*)*$`)
)
View Source
var SplitDIDURLRegexp, _ = regexp.Compile(`([^/?#]*)?([^?#]*)(\?([^#]*))?(#([^#]+$))?$`)

That for groups: Example: did:cheqd:testnet:fafdsffq11213343/path-to-s/ome-external-resource?query#key1??? 1 - [^/?#]* - all the symbols except / and ? and # . This is the DID part (did:cheqd:testnet:fafdsffq11213343) 2 - [^?#]* - all the symbols except ? and #. it means te section started from /, path-abempty (/path-to-s/ome-external-resource) 3 - \?([^#]*) - group for `query` part but with ? symbol (?query) 4 - [^#]* - group inside query string, match only exact query (query) 5 - #([^#]+[\$]?) - group for fragment, starts with #, includes # (#key1???) 6 - [^#]+[\$]? - fragment only (key1???) Number of queries is not limited.

View Source
var ValidURIRegexp, _ = regexp.Compile(`^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?`)

Goes from RFC: https://www.rfc-editor.org/rfc/rfc3986#appendix-B

Functions

func Contains

func Contains(vs []string, t string) bool

func Filter

func Filter(vs []string, f func(string) bool) []string

func GetTxHash

func GetTxHash(txBytes []byte) string

func IndexOf

func IndexOf(array []string, searchElement string, fromIndex int) int

func IsUnique

func IsUnique(list []string) bool

func IsValidBase58

func IsValidBase58(data string) bool

func IsValidDID

func IsValidDID(did string, method string, allowedNamespaces []string) bool

func IsValidDIDUrl

func IsValidDIDUrl(didUrl string, method string, allowedNamespaces []string) bool

func IsValidID

func IsValidID(id string) bool

func IsValidIndyId

func IsValidIndyId(data string) bool

func IsValidUUID

func IsValidUUID(u string) bool

func JoinDID

func JoinDID(method, namespace, id string) string

func JoinDIDUrl

func JoinDIDUrl(did string, path string, query string, fragment string) string

func MsgTypeURL

func MsgTypeURL(msg proto.Message) string

MsgTypeURL returns the TypeURL of a `proto.Message`.

func MustEncodeJson

func MustEncodeJson(data interface{}) string

func MustEncodeMultibaseBase58

func MustEncodeMultibaseBase58(data []byte) string

func MustSplitDID

func MustSplitDID(did string) (method string, namespace string, id string)

func MustSplitDIDUrl

func MustSplitDIDUrl(didUrl string) (did string, path string, query string, fragment string)

func NormalizeDID

func NormalizeDID(did string) string

func NormalizeDIDList

func NormalizeDIDList(didList []string) []string

func NormalizeDIDUrl

func NormalizeDIDUrl(didUrl string) string

func NormalizeDIDUrlList

func NormalizeDIDUrlList(didUrls []string) []string

func NormalizeId

func NormalizeId(id string) string

func NormalizeIdList

func NormalizeIdList(keys []string) []string

func NormalizeUUID

func NormalizeUUID(uuid string) string

func ReplaceInSlice

func ReplaceInSlice(list []string, old, new string)

func StrBytes

func StrBytes(p string) []byte

func Subtract

func Subtract(minuend []string, subtrahend []string) []string

func ToInterfaces

func ToInterfaces(list []string) []interface{}

func TrySplitDID

func TrySplitDID(did string) (method string, namespace string, id string, err error)

TrySplitDID Validates generic format of DID. It doesn't validate method, name and id content. Call ValidateDID for further validation.

func TrySplitDIDUrl

func TrySplitDIDUrl(didUrl string) (did string, path string, query string, fragment string, err error)

TrySplitDIDUrl Validates generic format of DIDUrl. It doesn't validate path, query and fragment content. Call ValidateDIDUrl for further validation.

func Unique

func Unique(array []string) []string

Unique returns a copy of the passed array with duplicates removed

func UniqueSorted

func UniqueSorted(ls []string) []string

func ValidateBase58

func ValidateBase58(data string) error

func ValidateDID

func ValidateDID(did string, method string, allowedNamespaces []string) error

ValidateDID checks method and allowed namespaces only when the corresponding parameters are specified.

func ValidateDIDUrl

func ValidateDIDUrl(didUrl string, method string, allowedNamespaces []string) error

ValidateDIDUrl checks method and allowed namespaces only when the corresponding parameters are specified.

func ValidateEd25519PubKey

func ValidateEd25519PubKey(keyBytes []byte) error

func ValidateFragment

func ValidateFragment(fragment string) error

func ValidateID

func ValidateID(id string) error

func ValidateJWK

func ValidateJWK(jwk_string string) error

func ValidateMultibase

func ValidateMultibase(data string) error

func ValidateMultibaseEncoding

func ValidateMultibaseEncoding(data string, expectedEncoding multibase.Encoding) error

func ValidatePath

func ValidatePath(path string) error

func ValidateQuery

func ValidateQuery(query string) error

func ValidateURI

func ValidateURI(uri string) error

func ValidateUUID

func ValidateUUID(u string) error

func VerifyECDSASignature

func VerifyECDSASignature(pubKey ecdsa.PublicKey, message []byte, signature []byte) error

VerifyECDSASignature uses ASN1 to decode r and s, SHA265 to calculate message digest

func VerifyED25519Signature

func VerifyED25519Signature(pubKey ed25519.PublicKey, message []byte, signature []byte) error

func VerifyRSASignature

func VerifyRSASignature(pubKey rsa.PublicKey, message []byte, signature []byte) error

VerifyRSASignature uses PSS padding and SHA256 digest A good explanation of different paddings: https://security.stackexchange.com/questions/183179/what-is-rsa-oaep-rsa-pss-in-simple-terms

Types

This section is empty.

Jump to

Keyboard shortcuts

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