Functions

The following functions are available globally.

Base32 Data <-> String

  • Encodes data to base32 string using the standard alphabet.

    Uses the standard base32 alphabet (A-Z, 2-7) as defined in RFC 4648.

    Example:

    let data = Data([1, 2, 3, 4, 5])
    let encoded = base32Encode(data)
    

    Declaration

    Swift

    public func base32Encode(_ data: Data) -> String

    Parameters

    data

    Data to encode

    Return Value

    Base32-encoded string

  • Encodes data to base32 string using the extended hex alphabet.

    Uses the extended hex alphabet (0-9, A-V) as defined in RFC 4648.

    Declaration

    Swift

    public func base32HexEncode(_ data: Data) -> String

    Parameters

    data

    Data to encode

    Return Value

    Base32hex-encoded string

  • Decodes a base32 string to data using the standard alphabet.

    Example:

    if let decoded = base32DecodeToData("AEBAGBA") {
        // Use decoded data
    }
    

    Declaration

    Swift

    public func base32DecodeToData(_ string: String) -> Data?

    Parameters

    string

    Base32-encoded string

    Return Value

    Decoded data, or nil if the string is invalid

  • Decodes a base32hex string to data using the extended hex alphabet.

    Declaration

    Swift

    public func base32HexDecodeToData(_ string: String) -> Data?

    Parameters

    string

    Base32hex-encoded string

    Return Value

    Decoded data, or nil if the string is invalid

Base32 [UInt8] <-> String

  • Encodes a byte array to base32 string using the standard alphabet.

    Declaration

    Swift

    public func base32Encode(_ array: [UInt8]) -> String

    Parameters

    array

    Byte array to encode

    Return Value

    Base32-encoded string

  • Encodes a byte array to base32 string using the extended hex alphabet.

    Declaration

    Swift

    public func base32HexEncode(_ array: [UInt8]) -> String

    Parameters

    array

    Byte array to encode

    Return Value

    Base32hex-encoded string

  • Decodes a base32 string to a byte array using the standard alphabet.

    Declaration

    Swift

    public func base32Decode(_ string: String) -> [UInt8]?

    Parameters

    string

    Base32-encoded string

    Return Value

    Decoded byte array, or nil if the string is invalid

  • Decodes a base32hex string to a byte array using the extended hex alphabet.

    Declaration

    Swift

    public func base32HexDecode(_ string: String) -> [UInt8]?

    Parameters

    string

    Base32hex-encoded string

    Return Value

    Decoded byte array, or nil if the string is invalid

BDouble more Operators

  • Returns the absolute value of the given number.

    Declaration

    Swift

    public func abs(_ x: BDouble) -> BDouble

    Parameters

    x

    a big double

  • round to largest BInt value not greater than base

    Declaration

    Swift

    public func floor(_ base: BDouble) -> BInt
  • round to smallest BInt value not less than base

    Declaration

    Swift

    public func ceil(_ base: BDouble) -> BInt
  • Returns a BDouble number raised to a given power.

    Declaration

    Swift

    public func pow(_ base: BDouble, _ exp: Int) -> BDouble
  • Orders two SCValXDR values the way the Soroban host orders ScMap keys.

    The host stores and validates ScMap keys in this order and rejects a contract argument map whose keys are out of order with InvalidInput.

    Ordering (rs-soroban-env Compare<ScVal>):

    • Values of different types compare by their SCValType discriminant.
    • I32, I64 and LedgerKeyNonce compare numerically as signed values; I128 and I256 compare the signed high part first, then the unsigned lower parts.
    • Vec compares element-wise (recursively); the shorter vec sorts first on a prefix tie.
    • Map compares entry-wise (key, then value, recursively); the map with fewer entries sorts first on a prefix tie.
    • Bytes, String, Symbol, and ExecutableTag compare by content, byte for byte (unsigned); the shorter value sorts first on a prefix tie.
    • ContractInstance compares by executable (type, then payload; an external reference by owner, then tag content), then by storage; absent storage sorts first.
    • All remaining types (Bool, Void, Error, the unsigned integers, Timepoint, Duration, Address, LedgerKeyContractInstance) consist of non-negative big-endian fields in XDR field order, so their XDR encodings compare in host order.

    Declaration

    Swift

    public func compareScValHostOrder(_ a: SCValXDR, _ b: SCValXDR) -> Int

    Parameters

    a

    The first value to compare.

    b

    The second value to compare.

    Return Value

    A negative value when a sorts before b, zero when the two values are equal under the host order, and a positive value when a sorts after b.