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:
- SEP-0008 Specification
- [StellarToml] for discovering regulated assets
-
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 -
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.invalidTomlif TOML data is invalid or missing required fields.Declaration
Swift
public init(tomlData: StellarToml, horizonUrl: String? = nil, network: Network? = nil) throwsParameters
tomlDataThe parsed stellar.toml file containing regulated asset information.
horizonUrlOptional custom Horizon API URL. If not provided, uses URL from TOML or network default.
networkOptional network specification. If not provided, derives from TOML’s network passphrase.
-
forDomain(domain:AsynchronoushorizonUrl: network: ) 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.tomland extracts regulated asset information.Declaration
Swift
public static func forDomain(domain: String, horizonUrl: String? = nil, network: Network? = nil) async -> RegulatedAssetsServiceForDomainEnumParameters
domainThe issuer’s domain including scheme (e.g., “https://issuer.example.com”)
horizonUrlOptional custom Horizon API URL. If not provided, uses URL from TOML or network default.
networkOptional network specification. If not provided, derives from TOML’s network passphrase.
Return Value
RegulatedAssetsServiceForDomainEnum with the service instance, or an error
-
authorizationRequired(asset:Asynchronous) 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 -> AuthorizationRequiredEnumParameters
assetThe regulated asset to check.
Return Value
AuthorizationRequiredEnumindicating whether authorization is required or if the check failed. -
postTransaction(txB64Xdr:AsynchronousapporvalServer: ) 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 -> PostSep08TransactionEnumParameters
txB64XdrThe transaction envelope in base64-encoded XDR format
apporvalServerThe URL of the SEP-08 approval server
Return Value
PostSep08TransactionEnum with the approval result (success, revised, pending, actionRequired, or rejected)
-
postAction(url:AsynchronousactionFields: ) 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 -> PostSep08ActionEnumParameters
urlThe action URL provided by the approval server.
actionFieldsDictionary of field names and values to submit.
Return Value
PostSep08ActionEnumindicating the result of the action submission.
View on GitHub
Install in Dash