Overview
The Identity Plugin manages cryptographic identities for interacting with the Internet Computer. It supports:- Seed Phrase Identities: Create identities from BIP39 mnemonic phrases
- Anonymous Identities: For testing and privacy-focused applications
- Identity Switching: Seamlessly switch between multiple identities
- Secure Storage: In-memory identity management with proper cleanup
Methods
generateSeedPhrase(wordCount?)
Generate a new BIP39 mnemonic seed phrase.
Parameters:
wordCount(optional):12 | 24- Number of words (default: 12)
string - Generated seed phrase
Example:
createFromSeedPhrase(seedPhrase, key?)
Create an identity from a seed phrase.
Parameters:
seedPhrase:string | string[]- BIP39 mnemonic phrasekey(optional):string- Unique key for the identity (auto-generated if not provided)
Promise<IIdentityCreationResult>
identity:Secp256k1KeyIdentity- Created identityinfo:IIdentityInfo- Identity information
createAnonymous(key?)
Create an anonymous identity.
Parameters:
key(optional):string- Unique key for the identity (auto-generated if not provided)
Promise<IIdentityCreationResult>
Example:
switch(key)
Switch to a different identity.
Parameters:
key:string- Key of the identity to switch to
Promise<void>
Example:
remove(key)
Remove an identity from storage.
Parameters:
key:string- Key of the identity to remove
void
Example:
list()
Get a list of all stored identity keys.
Returns: string[] - Array of identity keys
Example:
getCurrentKey()
Get the key of the currently active identity.
Returns: string - Current identity key
Example:
getInfo()
Get detailed information about the current identity.
Returns: Promise<IIdentityInfo>
type:IdentityType- Type of identity (secp256k1, anonymous)principal:Principal- Identity principalaccountId:string- ICP account identifierisAnonymous:boolean- Whether identity is anonymous
getPrincipal()
Get the principal of the current identity.
Returns: string - Principal as string
Example:
getAccountId()
Get the ICP account identifier of the current identity.
Returns: string - Account identifier
Example:
Types
IIdentityCreationResult
Result of identity creation operations.
IIdentityInfo
Detailed information about an identity.
IdentityType
Type of identity.
Usage Patterns
Multi-Wallet Management
Development with Anonymous Identities
Identity Lifecycle Management
Security Considerations
- Seed Phrase Storage: Never log or expose seed phrases. Store them securely outside the application.
-
Identity Cleanup: Use
agent.destroy()to properly clean up identities when done. - Anonymous vs Secp256k1: Use anonymous identities only for testing. Use secp256k1 identities for production applications.
- Principal Validation: Always validate principals before using them in operations.