Skip to main content

Class: AliasManager

The Alias Manager in the One37ID SDK is responsible for managing aliases, which are identifiers that can be used to represent entities (such as users or organizations) within the system. This manager allows for a range of operations related to aliases, such as creating new aliases, enabling or disabling them, checking their availability, and syncing or moving them between wallets. The Alias Manager helps ensure that aliases are unique and can be managed effectively across different connections.

Method: getList

The getList() method retrieves a list of aliases from the system. These aliases are categorized into two types: Current and Others. The method allows you to specify which type of aliases you want to fetch by passing the corresponding AliasConnectionType value.

  • Purpose: The purpose of the getList() method is to retrieve a list of aliases, either the current aliases associated with the wallet or other aliases that may not be currently connected.

  • Parameters:

    • aliasConnectionType: AliasConnectionType — Specifies the type of aliases to retrieve.
      • 0 for Current aliases.
      • 1 for Others aliases.
  • Returns: Promise<OperationDataResult<Alias[]>> — Resolves to an OperationDataResult object containing an array of Alias objects. If unsuccessful, it returns an error message.

Usage Example

This example demonstrates how to retrieve both the current aliases and other aliases using the getList() method.

// Retrieve current aliases
const currentAliases = await agent.aliasManager.getList(0); // 0 for Current
if (!currentAliases.isSuccessful) {
console.error('Failed to fetch current aliases:', currentAliases.error);
} else {
console.log('Current Aliases:', currentAliases.result);
}

// Retrieve other aliases
const otherAliases = await agent.aliasManager.getList(1); // 1 for Others
if (!otherAliases.isSuccessful) {
console.error('Failed to fetch other aliases:', otherAliases.error);
} else {
console.log('Other Aliases:', otherAliases.result);
}

Example Output (Success - Current Aliases):

{
"isSuccessful": true,
"result": [
{
"id": "alias1-id",
"alias": "alias1",
"status": "enabled"
},
{
"id": "alias2-id",
"alias": "alias2",
"status": "enabled"
}
]
}

Common Use Cases

  • Fetching Current Aliases: Use the getList() method to retrieve the current aliases connected to the wallet.

  • Fetching Other Aliases: Use the method to retrieve aliases that are not currently connected to the wallet but exist in the system.


Method: create

The create() method allows you to create a new alias in the system. An alias can be a representation of an identity within the wallet, and this method provides the ability to specify various parameters, such as the alias name, type, display name, and whether the alias should be incognito. However, creating a default alias is not allowed.

  • Purpose: The purpose of the create() method is to add a new alias to the system. This method ensures that aliases can be created with various configurations, except for default aliases, which are restricted.

  • Parameters:

    • model: CreateAlias — The object containing the alias creation details:
      • alias: string — The alias name.
      • type?: AliasType — (Optional) The type of alias (default aliases are not allowed).
      • displayName?: string — (Optional) The display name for the alias.
      • isIncognito?: boolean — (Optional) Whether the alias should be incognito or public.
  • Returns: Promise<OperationResult> — Resolves to an OperationResult object indicating whether the alias was successfully created. If unsuccessful, it returns an error message.

Usage Example

This example demonstrates how to create a new alias.

// Define the alias details
const aliasData = {
alias: 'myNewAlias', // Hardcoded alias name
displayName: 'My Alias', // Optional display name
isIncognito: false // Optional incognito setting
};

// Create the alias
const result = await agent.aliasManager.create(aliasData);

if (!result.isSuccessful) {
console.error(`Failed to create alias. Error: ${result.error}`);
} else {
console.log('Alias created successfully.');
}

Example Output (Success)

{
"isSuccessful": true
}

Common Use Cases

  • Creating a New Alias: Use the create() method to add a new alias to the system with custom configurations, such as an incognito mode or a display name.

  • Restricting Default Alias Creation: This method prevents the creation of default aliases, ensuring that only non-default aliases can be added.


Method: enable

The enable() method is used to activate or enable an alias that has been previously created. This ensures that the alias becomes available for use within the system. The alias must be identified by its unique ID.

  • Purpose: The purpose of the enable() method is to enable a previously created alias, allowing it to be used in the system. This method ensures that aliases can be toggled between enabled and disabled states.

  • Parameters:

    • id: string — The unique identifier of the alias you want to enable.
  • Returns: Promise<OperationResult> — Resolves to an OperationResult object indicating whether the alias was successfully enabled. If unsuccessful, it returns an error message.

Usage Example

This example demonstrates how to enable an alias by its ID.

// Alias ID to enable
const aliasId = 'alias-id-12345';

// Enable the alias
const result = await agent.aliasManager.enable(aliasId);

if (!result.isSuccessful) {
console.error(`Failed to enable alias. Error: ${result.error}`);
} else {
console.log('Alias enabled successfully.');
}

Example Output (Success)

{
"isSuccessful": true
}

Common Use Cases

  • Reactivating an Alias: Use this method to enable aliases that may have been previously disabled or inactive.

  • Managing Alias Availability: This method is essential for toggling alias states, ensuring that aliases can be made available or unavailable as needed.


Method: disable

The disable() method is used to deactivate or disable an alias, making it unavailable for use within the system. Once disabled, the alias remains in the system but cannot be actively used until it is re-enabled.

  • Purpose: The purpose of the disable() method is to deactivate a specific alias, preventing it from being used. This is useful for managing inactive aliases or temporarily disabling them without deleting them from the system.

  • Parameters:

    • id: string — The unique identifier of the alias you want to disable.
  • Returns: Promise<OperationResult> — Resolves to an OperationResult object indicating whether the alias was successfully disabled. If unsuccessful, it returns an error message.

Usage Example

This example demonstrates how to disable an alias by its ID.

// Alias ID to disable
const aliasId = 'alias-id-12345'; // Hardcoded alias ID

// Disable the alias
const result = await agent.aliasManager.disable(aliasId);

if (!result.isSuccessful) {
console.error(`Failed to disable alias. Error: ${result.error}`);
} else {
console.log('Alias disabled successfully.');
}

Example Output (Success)

{
"isSuccessful": true
}

Example Output (Failure - Unexpected Error)

{
"isSuccessful": false,
"errorCode": "UnexpectedError",
"error": "Failed to disable alias. Details: [error message]"
}

Common Use Cases

  • Temporarily Disabling an Alias: Use this method to deactivate an alias that you do not want to delete but wish to make unavailable temporarily.

  • Managing Alias States: This method is useful for toggling alias availability when certain aliases are no longer needed or are inactive.

Method: delete

The delete() method is used to permanently remove an alias from the system. Once an alias is deleted, it cannot be used again and is fully removed from the list of aliases.

  • Purpose: The purpose of the delete() method is to permanently remove an alias from the system. This is useful for cleaning up unused or unnecessary aliases that are no longer needed.

  • Parameters:

    • id: string — The unique identifier of the alias you want to delete.
  • Returns: Promise<OperationResult> — Resolves to an OperationResult object indicating whether the alias was successfully deleted. If unsuccessful, it returns an error message.

Usage Example

This example demonstrates how to delete an alias by its ID.

// Alias ID to delete
const aliasId = 'alias-id-12345'; // Hardcoded alias ID

// Delete the alias
const result = await agent.aliasManager.delete(aliasId);

if (!result.isSuccessful) {
console.error(`Failed to delete alias. Error: ${result.error}`);
} else {
console.log('Alias deleted successfully.');
}

Example Output (Success)

{
"isSuccessful": true
}

Example Output (Failure - Unexpected Error)

{
"isSuccessful": false,
"errorCode": "UnexpectedError",
"error": "Failed to delete alias. Details: [error message]"
}

Common Use Cases

  • Removing Unused Aliases: Use this method to permanently delete aliases that are no longer needed in the system.

  • Clearing Out Obsolete Aliases: This method is useful when cleaning up old or obsolete aliases from the system to prevent clutter and maintain the integrity of active aliases.


Method: isAvailable

The isAvailable() method checks whether a specified alias is available for use in the system. This method is useful for ensuring that a chosen alias is not already taken or reserved before creating it.

  • Purpose: The purpose of the isAvailable() method is to verify the availability of a given alias in the system. It helps prevent alias duplication by confirming if the alias is free to use.

  • Parameters:

    • model: AliasCheckAvailability — The object containing alias information to be checked for availability:
      • alias: string — The alias name to check.
      • type?: AliasType — (Optional) The type of alias.
  • Returns: Promise<OperationDataResult<boolean>> — Resolves to an OperationDataResult object with a boolean value indicating whether the alias is available (true) or not (false). If unsuccessful, it returns an error message.

Usage Example

This example demonstrates how to check if an alias is available for use.

// Alias to check for availability
const aliasCheck = {
alias: 'myAlias', // Hardcoded alias name
};

// Check if the alias is available
const result = await agent.aliasManager.isAvailable(aliasCheck);

if (!result.isSuccessful) {
console.error(`Failed to check alias availability. Error: ${result.error}`);
} else if (result.result) {
console.log('Alias is available.');
} else {
console.log('Alias is already taken.');
}

Example Output (Available)

{
"isSuccessful": true,
"result": true
}

Example Output (Not Available)

{
"isSuccessful": true,
"result": false
}

Example Output (Failure - Unexpected Error)

{
"isSuccessful": false,
"errorCode": "UnexpectedError",
"error": "Failed to check alias availability. Details: [error message]"
}

Common Use Cases

  • Checking Alias Availability Before Creation: Use this method to verify if a desired alias is available before creating it in the system.

  • Preventing Alias Duplication: This method ensures that an alias is not already taken or reserved, preventing duplicate or conflicting aliases.


Method: moveToCurrentWallet

The moveToCurrentWallet() method is used to transfer an alias to the current wallet. This method ensures that the specified alias is moved from another wallet or connection to the user's current wallet, making it active and usable in the current context.

  • Purpose: The purpose of the moveToCurrentWallet() method is to move an alias from another connection or wallet to the current wallet, ensuring it is available for use in the current environment.

  • Parameters:

    • id: string — The unique identifier of the alias that you want to move to the current wallet.
  • Returns: Promise<OperationResult> — Resolves to an OperationResult object indicating whether the alias was successfully moved to the current wallet. If unsuccessful, it returns an error message.

Usage Example

This example demonstrates how to move an alias to the current wallet by its ID.

// Alias ID to move to the current wallet
const aliasId = 'alias-id-12345'; // Hardcoded alias ID

// Move the alias to the current wallet
const result = await agent.aliasManager.moveToCurrentWallet(aliasId);

if (!result.isSuccessful) {
console.error(`Failed to move alias to current wallet. Error: ${result.error}`);
} else {
console.log('Alias successfully moved to the current wallet.');
}

Example Output (Success)

{
"isSuccessful": true
}

Example Output (Failure - Unexpected Error)

{
"isSuccessful": false,
"errorCode": "UnexpectedError",
"error": "Failed to move alias to current wallet. Details: [error message]"
}

Common Use Cases

  • Moving an Alias from One Wallet to Another: Use this method to move an alias from another connection or wallet to the current one, making it active in the current environment.

  • Managing Alias Ownership: This method is useful for transferring aliases between different wallets or contexts, ensuring that the alias is available where it is needed most.


Method: sync

The sync() method is used to synchronize aliases from the server to the current wallet. This ensures that any changes made to aliases on the server side are reflected in the current wallet, keeping the alias data up to date.

  • Purpose: The purpose of the sync() method is to synchronize the aliases from the server to the user's current wallet. This ensures that the latest changes and updates made to aliases on the server are reflected in the wallet, keeping alias data consistent.

  • Parameters:

    • None.
  • Returns: Promise<OperationResult> — Resolves to an OperationResult object indicating whether the alias synchronization was successful. If unsuccessful, it returns an error message.

Usage Example

This example demonstrates how to synchronize aliases with the current wallet.

// Synchronize aliases
const result = await agent.aliasManager.sync();

if (!result.isSuccessful) {
console.error(`Failed to sync aliases. Error: ${result.error}`);
} else {
console.log('Aliases successfully synchronized.');
}

Example Output (Success)

{
"isSuccessful": true
}

Example Output (Failure - Unexpected Error)

{
"isSuccessful": false,
"errorCode": "UnexpectedError",
"error": "Failed to sync aliases. Details: [error message]"
}

Common Use Cases

  • Synchronizing Alias Data: Use this method to keep alias data in sync between the server and the current wallet.

  • Ensuring Alias Consistency: This method ensures that the latest changes and updates to aliases on the server are applied to the current wallet.

X

Graph View