LogoLogo
  • Platform Overview
  • 🗺️Guides
    • Getting Started
    • Users
      • Integrate the User SDK
      • Registration
      • Authentication
      • SDK Releases
      • API Reference
    • Entitlements
      • Administrative API
        • Integrating the Administrative API
        • Entitlement Definitions
        • Managing Entitlements Sets
        • Managing Entitlements Sequences
        • Managing User Entitlements
        • API Schema
      • End-user API
        • Integrate the Entitlements SDK
        • Redeeming Entitlements
        • Retrieving Entitlements
        • SDK Releases
        • API Reference
    • Sudos
      • Integrate the Sudo Profiles SDK
      • Sudo Entitlements
      • Manage Sudos
      • SDK Releases
      • API Reference
    • Telephony
      • Integrate the Telephony SDK
      • Manage Phone Numbers
      • Text Messaging
      • Voice Calling
      • Telephony Simulator
      • SDK Releases
      • API Reference
    • Email
      • Integrate the Email SDK
      • Email Entitlements
      • Manage Email Addresses
      • Sending & Receiving Email
      • Manage Email Folders
      • Draft Email Messages
      • Manage Email Address Blocklists
      • Email Address Public Information
      • Pagination
      • Caching
      • Configuration Data
      • Email Notifications
      • SDK Releases
      • API Reference
    • Decentralized Identity
      • Edge Agent
        • Relay SDK
          • Integrate the Relay SDK
          • Relay Entitlements
          • Manage Relay Postboxes
          • Manage Relay Messages
          • Receiving Messages
          • SDK Releases
        • Edge Agent SDK
          • Integrate the Edge Agent SDK
          • Agent Management
          • Manage Wallets
          • Establishing Connections
          • Manage Connections
          • Messaging
          • Manage DIDs
          • Accepting New Credentials
          • Manage Credentials
          • Present Credentials for Verification
          • Utilize Alternative Cryptography Providers
          • SDK Releases
          • Standards and Protocols
      • Cloud Agent
        • Cloud Agent Admin API
          • Integrate the Cloud Agent Admin API
          • Aries Interop Profile (AIP)
            • Connection Exchanges
            • Credential Exchanges
            • Proof Exchanges
          • Connections
          • Basic Messages
          • Credentials
            • Anoncreds Credentials
              • Schemas
              • Credential Definitions
            • W3C Credentials
          • Audit Logs
          • API Schema
          • Error Codes
          • Standards and Protocols
    • Virtual Cards
      • Integrate the Virtual Cards SDK
      • Virtual Cards Entitlements
      • Virtual Cards Transaction Velocity Constraints
      • Key Management
      • Manage Funding Sources
      • Manage Virtual Cards
      • Manage Transactions
      • Configuration Data
      • Pagination
      • Caching
      • SDK Releases
      • API Reference
    • Virtual Cards Simulator
      • Integrate the Virtual Cards Simulator SDK
      • Simulate Authorizations
      • Simulate Debits
      • Simulate Refunds
      • Simulate Reversals
      • Merchants and Currencies
      • SDK Releases
      • API Reference
    • Virtual Private Network
      • Integrate the VPN SDK
      • VPN Entitlements
      • Manage Servers
      • Manage Connection
      • Observe VPN Related Events
      • SDK Releases
      • API Reference
      • Frequently Asked Questions
    • Secure ID Verification
      • Integrate the Secure ID Verification SDK
      • List Supported Countries
      • Verify an Identity
      • Check Secure ID Verification Status
      • Use the Secure ID Verification Simulator
      • SDK Releases
      • API Reference
    • Password Manager
      • Integrate the Password Manager SDK
      • Accessing the Password Manager
      • Managing Password Vaults
      • Managing Password Vault Items
      • Vault Import and Export
      • Password Utilities
      • Password Manager Entitlements
      • Password Vault Security
      • SDK Releases
      • API Reference
    • Ad/Tracker Blocker
      • Integrate the Ad/Tracker Blocker SDK
      • Manage Rulesets
      • Blocking Ads and Trackers
      • Manage Exceptions
      • SDK Releases
      • API Reference
    • Site Reputation
      • Integrate the Site Reputation SDK
      • Use the Site Reputation SDK
      • SDK Releases
      • API Reference
  • 💡Concepts
    • Sudo Digital Identities
  • 🧱Development
    • Versioning
  • 🏢Administration
    • Admin Console Roles
  • ❓Get Help
    • Request a Demo
    • Report an Issue
Powered by GitBook
On this page
  • Create Sudos
  • List Sudos
  • Modify Sudos
  • Subscribe to Changes
  • Delete Sudos
  • Get Ownership Proof
  • Resetting Client State
  1. Guides
  2. Sudos

Manage Sudos

Create Sudos

To create a new Sudo:

do {
    let sudoInput = SudoCreateInput(
        title: "Mr.", 
        firstName: "John", 
        lastName: "Smith",
        label: "Shopping", 
        notes: "Used for shopping.", 
        avatar: .fileUrl(avatarUrl)
    )
    let sudo = try await client.createSudo(input: sudoInput)
    // Create successful
} catch {
    // Handle error. An error may be thrown if the backend is unable
    // to create the Sudo due to availability, security or entitlement issues or
    // due to unrecoverable circumstances arising from programmatic error or 
    // configuration error. For example, if the keychain access entitlement 
    // is not set up correctly, the client is not signed in,
    // or basic system resources are unavailable.   
}
val sudo = Sudo()
sudo.title = "Mr."
sudo.firstName = "John"
sudo.lastName = "Smith"
sudo.label = "Shopping"
sudo.notes = "Used for shopping."
sudo.avatar = avatarUri

CoroutineScope(Dispatchers.IO).launch {
    try {
        client.createSudo(sudo)
        // Sudo created successfully.
    } catch (e: SudoProfileException) {
        // Handle error.
    }
}
import { Sudo } from '@sudoplatform/sudo-profiles'

const sudo = new Sudo()
sudo.title = "Mr."
sudo.firstName = "John"
sudo.lastName = "Smith"
sudo.label = "Shopping"
sudo.notes = "Used for shopping."
sudo.setAvatar(avatarFile)

try {
  const createdSudo = await client.createSudo(sudo)
  // Sudo created successfully.
} catch(err) {
  // Handle error.  
}

List Sudos

To list Sudos:

do {
    let sudos = try await client.listSudos(cachePolicy: .remoteOnly)
    // Download the avatar images.
    for sudo in sudos {
        if let avatarClaim = sudo.avatarClaim {
            let data = try await client.getBlob(forClaim: avatarClaim, cachePolicy: .remoteOnly)
            let image = UIImage(data: data)
        }
    }    
} catch {
    // Handle error. An error may be thrown if the backend is unable
    // to list Sudos due to availability or for unrecoverable circumstances arising
    // from programmatic error or configuration error. For example, if the keychain
    // access entitlement is not set up correctly, the client is not signed in,
    // or basic system resources are unavailable.
}
CoroutineScope(Dispatchers.IO).launch {
    try {
        val sudos = client.listSudos(ListOption.REMOTE_ONLY)
        for (sudo in sudos) {
            // Load the avatar image.
            val avatar = sudo.avatar
            if (avatar != null) {
                val file = File(avatar)
                val data = file.readBytes()
            }
        }

    } catch (e: SudoProfileException) {
        // Handle error.
    }
}
try {
  const sudos = await client.listSudos()
} catch(err) {
  // Handle error.
}

The cachePolicy parameter specifies whether to return the cached entries or fetch the data from the backend. Initially the cache will be empty but is populated the first time the data is fetched from the backend using remoteOnly option. If the app is offline or if it requires a separate action to fetch new data from the backend then use cacheOnly option to show the user with the last known state then update the view when the app is able to fetch new data from the backend. create, update and delete APIs can also update the cache but the cache needs to be hydrated first by invoke list API with remoteOnly.

Modify Sudos

To update an existing Sudo:

let updateInput = SudoUpdateInput(
    sudoId: sudoId, 
    version: version, 
    firstName: .newValue("David")
)
do {
    let updatedSudo = try await client.updateSudo(input: updateInput)
    // Update successful.
} catch {
    // Handle error. An error may be thrown if the backend is unable to
    // update Sudo due to availability or security issues or for unrecoverable 
    // circumstances arising from programmatic error or configuration error. 
    // For example, if the keychain access entitlement is not set up correctly, 
    // the client is not signed in, or basic system resources are unavailable.
}
sudo.firstName = "David"
CoroutineScope(Dispatchers.IO).launch {
    try {
        client.updateSudo(sudo)
        // Sudo updated successfully.
    } catch (e: SudoProfileException) {
        // Handle error.
    }
}
sudo.firstName = "David"
try {
  const updatedSudo = await client.updateSudo(sudo)
  // Sudo updated successfully.
} catch(err) {
  // Handle error.
}

Subscribe to Changes

To subscribe to a specific Sudo change notification:

class MySubscriber: SudoSubscriber {

    func sudoChanged(changeType: SudoChangeType, sudo: Sudo) {
        // Process new, updated or deleted Sudo.
    }

    func connectionStatusChanged(changeType: SudoChangeType, state: SubscriptionConnectionState) {
        if state == .connected {
            // The subscription for the provided change type is now connected hence the subscribers
            // will start receiving Sudo changes.
        } else if state == .disconnected {
            // The subscription is disconnected and all subscribers for the provided
            // change type were automatically unsubscribed. Subscribe again to establish a 
            // new connection or report the error.
        }
    }

}

let subscriber = MySubscriber()
do {
    try await client.subscribe(id: "subscriber_id", changeTypes: [.create], subscriber: subscriber)
} catch {
    // Handle error. An error might be thrown for unrecoverable circumstances arising
    // from programmatic error or configuration error. For example, if the keychain
    // access entitlement is not set up correctly, the client is not signed in,
    // or basic system resources are unavailable.
}
class MySubscriber: SudoSubscriber {

    override fun connectionStatusChanged(state: SudoSubscriber.ConnectionState) {
        if (state == SudoSubscriber.ConnectionState.CONNECTED) {
            // The subscription is now connected hence the subscribers
            // will start receiving Sudo changes.
        } else {
            // The subscription is disconnected and all subscribers were
            // automatically unsubscribed. Subscribe again to establish a 
            // new connection or report the error.        
        }
    }

    override fun sudoChanged(changeType: SudoSubscriber.ChangeType, sudo: Sudo) {
        // Process new, updated or deleted Sudo.
    }
}

val subscriber = MySubscriber()
CoroutineScope(Dispatchers.IO).launch {
    client.subscribeAsync("<subscriber_id>", SudoSubscriber.ChangeType.CREATE, subscriber)
}
import { 
  SudoSubscriber, 
  ConnectionState,
  ChangeType, 
  } from '@sudoplatform/sudo-profiles'

class MySubscriber implements SudoSubscriber {
  public sudoChanged(changeType, sudo) {
    // Process new, updated or deleted Sudo.
  }

  public connectionStatusChanged(state) {
    if (state === ConnectionState.Connected) {
        // The subscription is now connected hence the subscribers
        // will start receiving Sudo changes.
    } else {
        // The subscription is disconnected and all subscribers were
        // automatically unsubscribed. Subscribe again to establish a 
        // new connection or report the error.        
    }
  }    
}

try {
  const subscriber = new MySubscriber()
  client.subscribe('subscriber_id', ChangeType.Create, subscriber)
} catch(err) {
  // Handle error.
}

For creating a new Sudo, the subscribers will be notified twice: ".create" notification when the Sudo is created and ".update" notification when the Sudo is updated with claims that requires reference to Sudo ID. The request to create a Sudo is considered complete when both of notifications have been received.

To subscribe to Sudo change notification of all types:

class MySubscriber: SudoSubscriber {

    func sudoChanged(changeType: SudoChangeType, sudo: Sudo) {
        // Process new, updated or deleted Sudo.
    }

    func connectionStatusChanged(changeType: SudoChangeType, state: SubscriptionConnectionState) {
        if state == .connected {
            // The subscription is now connected hence the subscribers
            // will start receiving Sudo changes.
        } else if state == .disconnected {
            // The subscription is disconnected and all subscribers were
            // automatically unsubscribed. Subscribe again to establish a 
            // new connection or report the error.
        }
    }

}

let subscriber = MySubscriber()
do {
    try await client.subscribe(id: "subscriber_id", subscriber: subscriber)
} catch {
    // Handle error. An error may be thrown for unrecoverable circumstances arising
    // from programmatic error or configuration error. For example, if the keychain
    // access entitlement is not set up correctly, the client is not signed in,
    // or basic system resources are unavailable.
}
class MySubscriber: SudoSubscriber {

    override fun connectionStatusChanged(state: SudoSubscriber.ConnectionState) {
        if (state == SudoSubscriber.ConnectionState.CONNECTED) {
            // The subscription is now connected hence the subscribers
            // will start receiving Sudo changes.
        } else {
            // The subscription is disconnected and all subscribers were
            // automatically unsubscribed. Subscribe again to establish a 
            // new connection or report the error.        
        }
    }

    override fun sudoChanged(changeType: SudoSubscriber.ChangeType, sudo: Sudo) {
        // Process new, updated or deleted Sudo.
    }
}

val subscriber = MySubscriber()
CoroutineScope(Dispatchers.IO).launch {
    client.subscribeAsync("<subscriber_id>", subscriber)
}
import { 
  SudoSubscriber, 
  ConnectionState,
  ChangeType, 
  } from '@sudoplatform/sudo-profiles'

class MySubscriber implements SudoSubscriber {
  public sudoChanged(changeType, sudo) {
    // Process new, updated or deleted Sudo.
  }

  public connectionStatusChanged(state) {
    if (state === ConnectionState.Connected) {
        // The subscription is now connected hence the subscribers
        // will start receiving Sudo changes.
    } else {
        // The subscription is disconnected and all subscribers were
        // automatically unsubscribed. Subscribe again to establish a 
        // new connection or report the error.        
    }
  }    
}

try {
  const subscriber = new MySubscriber()
  client.subscribeAll('subscriber_id', subscriber)
} catch(err) {
  // Handle error.
}

Delete Sudos

To delete an existing Sudo:

let input = SudoDeleteInput(sudoId: sudoId, version: version)
do {
    try await client.deleteSudo(input: input) 
    // Delete successful.
} catch {
    // Handle error. An error might be thrown if the backend is unable 
    // to delete the Sudo due to availability or security issues or for 
    // unrecoverable circumstances arising from programmatic error or 
    // configuration error. For example, if the keychain access entitlement is 
    // not set up correctly, the client is not signed in, or basic system 
    // resources are unavailable.
}
CoroutineScope(Dispatchers.IO).launch {
    try {
        client.deleteSudo(sudo)
        // Sudo deleted successfully.
    } catch (e: SudoProfileException) {
        // Handle error.
    }
}
try {
  await client.deleteSudo(sudo)
  // Sudo deleted successfully.
} catch(err) {
  // Handle error.
}

Get Ownership Proof

Many Sudo Platform services require the user to present a proof that they own a particular Sudo so that a provisioned resource can be associated with a Sudo. Sudo Profiles SDK provides an API to generate a cryptographic proof of Sudo ownership so it can be used in provisioning APIs of other SDKs such as Email SDK.

To obtain a Sudo ownership proof for provisioning a resource tied to a Sudo.

do {
    let jwt = try await client.getOwnershipProof(sudo: sudo, audience: "<service_specific_audience>")
    // Ownership proof obtained successfully.
} catch {
    // Handle error. An error might be thrown if the backend is unable
    // to delete the Sudo due to availability or security issues or for 
    // unrecoverable circumstances arising from programmatic error or 
    // configuration error. For example, if the keychain access entitlement is 
    // not set up correctly, the client is not signed in, or basic system 
    // resources are unavailable.
}
CoroutineScope(Dispatchers.IO).launch {
    try {
        client.getOwnershipProof(sudo, "<service_specific_audience>")
        // Ownership proof obtained successfully.
    } catch (e: SudoProfileException) {
        // Handle error.
    }
}
try {
  await client.getOwnershipProof(sudoId, "<service_specific_audience>")
  // Ownership proof obtained successfully.
} catch(err) {
  // Handle error.
}

Resetting Client State

You can reset the internal state information maintained by SudoProfilesClient by calling reset API.

Resetting the client state will cause all persistent data to be lost including any cached Sudos and encryption keys. Unless you are intending to import the encryption keys from an external source, e.g. key backup, you should call generateEncryptionKey API to create a new encryption key before using SudoProfileClient again.

do {
    try await client.reset()
} catch {
    // Handle error. An error may be thrown for unrecoverable circumstances arising
    // from programmatic error or configuration error. For example, basic system resources
    // are not accessible.
}
client.reset()
try {
  await client.reset()
} catch(err) {
  // Handle error. An error might be thrown for unrecoverable circumstances arising
  // from programmatic error or configuration error. For example, basic system resources
  // are not accessible.
}
PreviousSudo EntitlementsNextSDK Releases

Last updated 28 days ago

🗺️