utils

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SuiAddressLength is the length of a Sui address in bytes
	SuiAddressLength = 32
	// TxDigestLength is the length of a transaction digest in bytes
	TxDigestLength = 32
)

Variables

View Source
var (
	// SuiDecimals is the number of decimals used in SUI tokens
	SuiDecimals = 9
	// MistPerSui is the number of mist per SUI token
	MistPerSui = 1000000000
	// GasSafeOverhead is the overhead for gas in SUI transactions
	GasSafeOverhead uint64 = 1000
	// MaxGas is the maximum gas limit for SUI transactions
	MaxGas uint64 = 50000000000
	// MoveStdlibAddress is the address of the Move standard library in SUI, 0x0000000000000000000000000000000000000000000000000000000000000001
	MoveStdlibAddress = NormalizeSuiObjectID("0x1")
	// SuiFrameworkAddress is the address of the SUI framework, 0x0000000000000000000000000000000000000000000000000000000000000002
	SuiFrameworkAddress = NormalizeSuiObjectID("0x2")
	// SuiSystemAddress is the address of the SUI system, 0x0000000000000000000000000000000000000000000000000000000000000003
	SuiSystemAddress = NormalizeSuiObjectID("0x3")
	// SuiClockObjectID is the object ID for SUI clock, 0x0000000000000000000000000000000000000000000000000000000000000006
	SuiClockObjectID = NormalizeSuiObjectID("0x6")
	// SuiSystemModuleName is the name of the SUI system module
	SuiSystemModuleName = "sui_system"
	// SuiTypeArg is the type argument for SUI, used in Move types, 0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI
	SuiTypeArg = fmt.Sprintf("%s::sui::SUI", SuiFrameworkAddress)
	// SuiSystemStateObjectID is the object ID for the SUI system state, 0x0000000000000000000000000000000000000000000000000000000000000005
	SuiSystemStateObjectID = NormalizeSuiObjectID("0x5")
)

Functions

func B64PublicKeyToSuiAddress

func B64PublicKeyToSuiAddress(b64 string) (string, error)

B64PublicKeyToSuiAddress converts a base64 encoded public key to a Sui address.

func B64ToSuiPrivateKey

func B64ToSuiPrivateKey(b64 string) (string, error)

B64ToSuiPrivateKey converts a base64 encoded Sui private key to a hex string representation.

func Ed25519PublicKeyToB64PublicKey

func Ed25519PublicKeyToB64PublicKey(ed25519PubKey ed25519.PublicKey) string

Ed25519PublicKeyToB64PublicKey converts an Ed25519 public key to a base64 encoded string.

func GetHexByteLength

func GetHexByteLength(v string) int

GetHexByteLength returns the number of bytes represented by a hex string.

func IsHex

func IsHex(v string) bool

IsHex checks if a string is a valid hexadecimal representation.

func IsValidSuiAddress

func IsValidSuiAddress(v string) bool

IsValidSuiAddress checks if a given Sui address is valid.

func IsValidSuiObjectID added in v0.0.6

func IsValidSuiObjectID(v string) bool

IsValidSuiObjectID checks if a given Sui object ID is valid.

func IsValidTransactionDigest

func IsValidTransactionDigest(v string) bool

IsValidTransactionDigest checks if a given transaction digest is valid.

func NormalizeShortSuiAddress

func NormalizeShortSuiAddress(v string) string

NormalizeShortSuiAddress normalizes a short Sui address string. 0x0000000000000000000000000000000000000000000000000000000000000001 -> 0x1

func NormalizeShortSuiCoinType

func NormalizeShortSuiCoinType(v string) string

NormalizeShortSuiCoinType normalizes a short Sui coin type string. 0x2::sui::SUI -> 0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI

func NormalizeShortSuiObjectID added in v0.0.6

func NormalizeShortSuiObjectID(v string) string

NormalizeShortSuiObjectID normalizes a short Sui object ID string. 0x0000000000000000000000000000000000000000000000000000000000000001 -> 0x1

func NormalizeSuiAddress

func NormalizeSuiAddress(v string) string

NormalizeSuiAddress normalizes a Sui address string to a standard format. *

  • Perform the following operations:

  • 1. Make the address lower case

  • 2. Prepend `0x` if the string does not start with `0x`.

  • 3. Add more zeros if the length of the address(excluding `0x`) is less than `SUI_ADDRESS_LENGTH` *

  • WARNING: if the address value itself starts with `0x`, e.g., `0x0x`, the default behavior

  • is to treat the first `0x` not as part of the address. The default behavior can be overridden by

  • setting `forceAdd0x` to true *

    0x1 -> 0x0000000000000000000000000000000000000000000000000000000000000001

func NormalizeSuiCoinType

func NormalizeSuiCoinType(v string) string

NormalizeSuiCoinType normalizes a Sui coin type string to a standard format. 0x2::sui::SUI -> 0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI

func NormalizeSuiObjectID added in v0.0.6

func NormalizeSuiObjectID(v string) string

NormalizeSuiObjectID normalizes a Sui object ID string to a standard format. 0x1 -> 0x0000000000000000000000000000000000000000000000000000000000000001

func ParseDevInspectReturnValue

func ParseDevInspectReturnValue(v [2]interface{}) ([]byte, error)

ParseDevInspectReturnValue parses the return value from a dev inspect call.

func SliceToMap

func SliceToMap[T any, V comparable](src []T, key func(T) V) map[V]T

SliceToMap converts a slice to a map using a key function to extract the key from each element.

func SuiPrivateKeyToB64

func SuiPrivateKeyToB64(pk string) (string, error)

SuiPrivateKeyToB64 converts a Sui private key in hex format to a base64 encoded string.

Types

type Endpoint added in v0.0.5

type Endpoint string

Endpoint represents a SUI network endpoint

const (
	// MainnetRPC is the RPC endpoint for the SUI mainnet
	MainnetRPC Endpoint = "https://fullnode.mainnet.sui.io"
	// TestnetRPC is the RPC endpoint for the SUI testnet
	TestnetRPC Endpoint = "https://fullnode.testnet.sui.io"
	// DevnetRPC is the RPC endpoint for the SUI devnet
	DevnetRPC Endpoint = "https://fullnode.devnet.sui.io"
	// LocalnetRPC is the RPC endpoint for the SUI localnet
	LocalnetRPC Endpoint = "http://127.0.0.1:9000"

	// MainnetWSS is the WebSocket endpoint for the SUI mainnet
	MainnetWSS Endpoint = "wss://fullnode.mainnet.sui.io"
	// TestnetWSS is the WebSocket endpoint for the SUI testnet
	TestnetWSS Endpoint = "wss://fullnode.testnet.sui.io"

	// TestnetFaucet is the faucet endpoint for the SUI testnet
	TestnetFaucet Endpoint = "https://faucet.testnet.sui.io/gas"
	// DevnetFaucet is the faucet endpoint for the SUI devnet
	DevnetFaucet Endpoint = "https://faucet.devnet.sui.io"
	// LocalnetFaucet is the faucet endpoint for the SUI localnet
	LocalnetFaucet Endpoint = "http://127.0.0.1:9123"
)

func (Endpoint) String added in v0.0.5

func (e Endpoint) String() string

type Network added in v0.0.5

type Network string

Network represents the SUI network type

const (
	// Mainnet is the main SUI network
	Mainnet Network = "mainnet"
	// Testnet is the test SUI network
	Testnet Network = "testnet"
	// Devnet is the development SUI network
	Devnet Network = "devnet"
	// Localnet is the local SUI network
	Localnet Network = "localnet"
)

func (Network) String added in v0.0.5

func (n Network) String() string

Jump to

Keyboard shortcuts

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