RegulatedAssetsService

public final class RegulatedAssetsService : @unchecked Sendable

Implements SEP-0008 - Regulated Assets.

This class enables issuers to validate and approve transactions involving regulated assets before they are submitted to the network. Regulated assets require issuer approval for transfers, ensuring compliance with securities regulations and KYC/AML requirements.

Typical Usage

// Initialize from domain
let result = await RegulatedAssetsService.forDomain(
    domain: "https://issuer.example.com",
    network: .public
)

guard case .success(let service) = result else { return }

// Build transaction
let transaction = try Transaction(...)
let txXdr = try transaction.encodedEnvelope()

// Submit for approval
let approvalResult = await service.postTransaction(
    txB64Xdr: txXdr,
    apporvalServer: service.regulatedAssets[0].approvalServer
)

switch approvalResult {
case .success(let response):
    // Transaction approved, submit to network
    let approvedTx = try Transaction(envelopeXdr: response.tx)
case .revised(let response):
    // Issuer revised transaction (e.g., added compliance fee)
    let revisedTx = try Transaction(envelopeXdr: response.tx)
case .pending(let response):
    // Approval pending, retry later
case .actionRequired(let response):
    // User action needed (e.g., complete KYC)
case .rejected(let response):
    // Transaction rejected
}

See also:

  • The parsed stellar.toml configuration containing regulated asset definitions and approval server URLs.

    Declaration

    Swift

    public let tomlData: StellarToml
  • The Stellar network this service operates on.

    Declaration

    Swift

    public let network: Network
  • sdk

    The StellarSDK instance used for Horizon API interactions.

    Declaration

    Swift

    public let sdk: StellarSDK
  • List of regulated assets discovered from the stellar.toml file.

    Declaration

    Swift

    public let regulatedAssets: [RegulatedAsset]
  • Creates a new RegulatedAssetsService instance from parsed TOML data.

    Throws

    RegulatedAssetsServiceError.invalidToml if TOML data is invalid or missing required fields.

    Declaration

    Swift

    public init(tomlData: StellarToml, horizonUrl: String? = nil, network: Network? = nil) throws

    Parameters

    tomlData

    The parsed stellar.toml file containing regulated asset information.

    horizonUrl

    Optional custom Horizon API URL. If not provided, uses URL from TOML or network default.

    network

    Optional network specification. If not provided, derives from TOML’s network passphrase.

  • Creates a RegulatedAssetsService instance based on information from the stellar.toml file for a given domain.

    Fetches the stellar.toml file from {domain}/.well-known/stellar.toml and extracts regulated asset information.

    Declaration

    Swift

    public static func forDomain(domain: String, horizonUrl: String? = nil, network: Network? = nil) async -> RegulatedAssetsServiceForDomainEnum

    Parameters

    domain

    The issuer’s domain including scheme (e.g., “https://issuer.example.com”)

    horizonUrl

    Optional custom Horizon API URL. If not provided, uses URL from TOML or network default.

    network

    Optional network specification. If not provided, derives from TOML’s network passphrase.

    Return Value

    RegulatedAssetsServiceForDomainEnum with the service instance, or an error

  • Checks if a regulated asset requires authorization flags.

    Queries the issuer account to determine if both AUTH_REQUIRED and AUTH_REVOCABLE flags are set.

    Declaration

    Swift

    public func authorizationRequired(asset: RegulatedAsset) async -> AuthorizationRequiredEnum

    Parameters

    asset

    The regulated asset to check.

    Return Value

    AuthorizationRequiredEnum indicating whether authorization is required or if the check failed.

  • Sends a transaction to be evaluated and signed by the approval server.

    The approval server validates the transaction against compliance requirements and may approve, revise, reject, or request additional action from the user.

    Declaration

    Swift

    public func postTransaction(txB64Xdr: String, apporvalServer: String) async -> PostSep08TransactionEnum

    Parameters

    txB64Xdr

    The transaction envelope in base64-encoded XDR format

    apporvalServer

    The URL of the SEP-08 approval server

    Return Value

    PostSep08TransactionEnum with the approval result (success, revised, pending, actionRequired, or rejected)

  • Posts action data to a SEP-08 action URL when user action is required.

    Used when the approval server returns an action_required status, requiring the user to provide additional information before transaction approval can proceed.

    Declaration

    Swift

    public func postAction(url: String, actionFields: [String : Any]) async -> PostSep08ActionEnum

    Parameters

    url

    The action URL provided by the approval server.

    actionFields

    Dictionary of field names and values to submit.

    Return Value

    PostSep08ActionEnum indicating the result of the action submission.