utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHexPrefix

func AddHexPrefix(str string) string

AddHexPrefix adds the "0x" prefix to a string if it does not already have it.

Parameters:

  • str: The string to add the prefix to.

Returns:

  • string: The string with the "0x" prefix.

func DecodeDomain

func DecodeDomain(encoded []*felt.Felt) string

DecodeDomain decodes a starknet.id domain from a list of felt.

Parameters:

  • encoded: The encoded domain.

Returns:

  • string: The decoded domain.

Examples:

  • DecodeDomain(nil) => ""
  • DecodeDomain([felt_0]) => ""
  • DecodeDomain([felt_abc]) => "abc.stark"
  • DecodeDomain([felt_def]) => "def.stark"
  • DecodeDomain([felt_ghi]) => "ghi.stark"
  • DecodeDomain([felt_abc, felt_def]) => "abc.def.stark"
  • DecodeDomain([felt_abc, felt_def, felt_ghi]) => "abc.def.ghi.stark"

func DecodeShortString added in v0.1.7

func DecodeShortString(str string) (string, error)

DecodeShortString decodes a string from its hexadecimal representation.

Parameters:

  • str: The string to decode.

Returns:

  • string: The decoded string.
  • error: An error if the string is not a hexadecimal or decimal string.

func EncodeDomain

func EncodeDomain(domain string) ([]*felt.Felt, error)

EncodeDomain encodes a starknet.id domain into a list of felt, with one felt per subdomain.

Parameters:

  • domain: The domain to encode (.stark suffix is optional).

Returns:

  • []*felt.Felt: The encoded domain.
  • error: An error if the encoding fails.

Examples:

  • EncodeDomain("") => [felt_0]
  • EncodeDomain("abc.stark") => [felt_abc]
  • EncodeDomain("abc") => [felt_abc]
  • EncodeDomain("def.stark") => [felt_def]
  • EncodeDomain("ghi.stark") => [felt_ghi]
  • EncodeDomain("abc.def.stark") => [felt_abc, felt_def]
  • EncodeDomain("abc.def.ghi.stark") => [felt_abc, felt_def, felt_ghi]
  • EncodeDomain("αβγ.stark") => error failed to encode subdomain αβγ: invalid character α

func EncodeShortString

func EncodeShortString(str string) (*felt.Felt, error)

EncodeShortString encodes a string to its hexadecimal representation with a "0x" prefix.

Parameters:

  • str: The string to encode.

Returns:

  • *felt.Felt: The encoded string.
  • error: An error if the string is not an ASCII string or is too long.

func FmtFeltArrayCallData

func FmtFeltArrayCallData(callData []*felt.Felt) []*felt.Felt

FmtFeltArrayCallData formats an array call data: [len(callData), callData...]

Parameters:

  • callData: The call data to format.

Returns:

  • []*felt.Felt: The formatted call data.

func GetBlobbertContract

func GetBlobbertContract(chainId types.StarknetChainId) (string, error)

GetBlobbertContract returns the blobbert contract address for a given chain.

Parameters:

  • chainId: The chain ID.

Returns:

  • string: The blobbert contract address.
  • error: An error if the blobbert contract is not deployed on the chain.

func GetIdentityContract

func GetIdentityContract(chainId types.StarknetChainId) (string, error)

GetIdentityContract returns the identity contract address for a given chain.

Parameters:

  • chainId: The chain ID.

Returns:

  • string: The identity contract address.
  • error: An error if the identity contract is not deployed on the chain.

func GetMulticallContract

func GetMulticallContract(chainId types.StarknetChainId) (string, error)

GetMulticallContract returns the multicall contract address for a given chain.

Parameters:

  • chainId: The chain ID.

Returns:

  • string: The multicall contract address.
  • error: An error if the multicall contract is not deployed on the chain.

func GetNamingContract

func GetNamingContract(chainId types.StarknetChainId) (string, error)

GetNamingContract returns the naming contract address for a given chain.

Parameters:

  • chainId: The chain ID.

Returns:

  • string: The naming contract address.
  • error: An error if the naming contract is not deployed on the chain.

func GetPfpVerifierContract

func GetPfpVerifierContract(chainId types.StarknetChainId) (string, error)

GetPfpVerifierContract returns the profile picture verifier contract address for a given chain.

Parameters:

  • chainId: The chain ID.

Returns:

  • string: The profile picture verifier contract address.
  • error: An error if the profile picture verifier contract is not deployed on the chain.

func GetPopVerifierContract

func GetPopVerifierContract(chainId types.StarknetChainId) (string, error)

GetPopVerifierContract returns the proof of personhood verifier contract address for a given chain.

Parameters:

  • chainId: The chain ID.

Returns:

  • string: The proof of personhood verifier contract address.
  • error: An error if the proof of personhood verifier contract is not deployed on the chain.

func GetUtilsMulticallContract

func GetUtilsMulticallContract(chainId types.StarknetChainId) (string, error)

GetUtilsMulticallContract returns the utils multicall contract address for a given chain.

Parameters:

  • chainId: The chain ID.

Returns:

  • string: The utils multicall contract address.
  • error: An error if the utils multicall contract is not deployed on the chain.

func GetVerifierContract

func GetVerifierContract(chainId types.StarknetChainId) (string, error)

GetVerifierContract returns the verifier contract address for a given chain.

Parameters:

  • chainId: The chain ID.

Returns:

  • string: The verifier contract address.
  • error: An error if the verifier contract is not deployed on the chain.

func IsASCII

func IsASCII(str string) bool

IsASCII checks if a string contains only ASCII characters.

Parameters:

  • str: The string to check.

Returns:

  • bool: True if the string contains only ASCII characters, false otherwise.

func IsBraavosSubdomain

func IsBraavosSubdomain(domain string) bool

IsBraavosSubdomain checks if a domain is a Braavos subdomain based on the following regular expression: `^([a-z0-9-]){1,48}\.braavos\.stark$`

Parameters:

  • domain: The domain to check.

Returns:

  • bool: True if the domain is a Braavos subdomain, false otherwise.

func IsDecimalString added in v0.1.7

func IsDecimalString(str string) bool

IsDecimalString checks if a string is a decimal string.

Parameters:

  • str: The string to check.

Returns:

  • bool: True if the string is a decimal string, false otherwise.

func IsHex added in v0.1.7

func IsHex(str string) bool

IsHex checks if a string is a hexadecimal string.

Parameters:

  • str: The string to check.

Returns:

  • bool: True if the string is a hexadecimal string, false otherwise.

func IsShortString

func IsShortString(str string) bool

IsShortString checks if the length of a string is valid for a short string.

Parameters:

  • str: The string to check.

Returns:

  • bool: True if the string is a short string, false otherwise.

func IsStarkDomain

func IsStarkDomain(domain string) bool

IsStarkDomain checks if a domain is a starknet.id domain based on the following regular expression: `^(?:[a-z0-9-]{1,48}(?:[a-z0-9-]{1,48}[a-z0-9-])?\.)*[a-z0-9-]{1,48}\.stark$`

Parameters:

  • domain: The domain to check.

Returns:

  • bool: True if the domain is a starknet.id domain, false otherwise.

func IsStarkRootDomain

func IsStarkRootDomain(domain string) bool

IsStarkRootDomain checks if a domain is a stark root domain based on the following regular expression: `^([a-z0-9-]){1,48}\.stark$`

Parameters:

  • domain: The domain to check.

Returns:

  • bool: True if the domain is a stark root domain, false otherwise.

func IsSubdomain

func IsSubdomain(subdomain string) bool

IsSubdomain checks if a domain is a subdomain.

Parameters:

  • subdomain: The domain to check.

Returns:

  • bool: True if the domain is a subdomain, false otherwise.

func IsXplorerSubdomain

func IsXplorerSubdomain(domain string) bool

IsXplorerSubdomain checks if a domain is an xplorer subdomain based on the following regular expression: `^([a-z0-9-]){1,48}\.xplorer\.stark$`

Parameters:

  • domain: The domain to check.

Returns:

  • bool: True if the domain is an xplorer subdomain, false otherwise.

func RemoveHexPrefix added in v0.1.7

func RemoveHexPrefix(str string) string

RemoveHexPrefix removes the "0x" prefix from a string if it has it.

Parameters:

  • str: The string to remove the prefix from.

Returns:

  • string: The string without the "0x" prefix.

Types

This section is empty.

Jump to

Keyboard shortcuts

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