管理身份,支持身份的创建、登录、登出、更新和导入导出等操作
构造函数
const identityManager = new IdentityManager() Copy
const identityManager = new IdentityManager()
创建新身份,生成 BlockAddress 并加密存储,同时缓存登录信息
身份密码
身份模板
返回创建的身份信息
const template = { code: IdentityCodeEnum.IDENTITY_CODE_PERSONAL }const identity = await identityManager.createIdentity('example-password', template) Copy
const template = { code: IdentityCodeEnum.IDENTITY_CODE_PERSONAL }const identity = await identityManager.createIdentity('example-password', template)
导出身份信息为 JSON 字符串,验证身份的完整性和合法性后返回序列化的身份信息
身份的 DID
返回身份的 JSON 字符串
const identityJson = await identityManager.exportIdentity('example-did') Copy
const identityJson = await identityManager.exportIdentity('example-did')
获取当前登录的身份 DID
返回当前登录的 DID,如果未登录则返回 undefined
const activeDid = identityManager.getActiveDid() Copy
const activeDid = identityManager.getActiveDid()
获取当前登录的身份信息
返回当前登录的身份对象,如果未登录则返回 undefined
const activeIdentity = await identityManager.getActiveIdentity() Copy
const activeIdentity = await identityManager.getActiveIdentity()
获取身份的 BlockAddress
返回解密后的 BlockAddress
const blockAddress = await identityManager.getBlockAddress('example-did') Copy
const blockAddress = await identityManager.getBlockAddress('example-did')
获得当前身份状态
获取历史登录记录
返回历史登录的 DID 列表
const history = identityManager.getHistory() Copy
const history = identityManager.getHistory()
获取身份信息,如果身份已缓存,则直接返回;否则从本地缓存中加载并验证
返回身份信息
const identity = await identityManager.getIdentity('example-did') Copy
const identity = await identityManager.getIdentity('example-did')
获取当前节点信息
Optional
可选的节点域名(默认为当前窗口的域名)
返回节点的元数据
const nodeMetadata = await identityManager.getNode() Copy
const nodeMetadata = await identityManager.getNode()
导入身份信息,从 JSON 字符串导入身份,解密 BlockAddress 并缓存登录信息
身份的 JSON 字符串
返回导入的身份信息
InvalidPassword 密码错误
const identity = await identityManager.importIdentity(identityJson, 'example-password') Copy
const identity = await identityManager.importIdentity(identityJson, 'example-password')
检查是否已登录指定身份
如果已登录,返回 true;否则返回 false
const isLogged = identityManager.isLogin('example-did') Copy
const isLogged = identityManager.isLogin('example-did')
登录身份,解密身份信息
登录密码
返回登录的身份信息
const identity = await identityManager.login('example-did', 'example-password') Copy
const identity = await identityManager.login('example-did', 'example-password')
登出当前身份
identityManager.logout() Copy
identityManager.logout()
更新身份信息, 解密 BlockAddress 并使用新的模板信息更新身份
部分更新的身份模板
身份密码,如果已登陆可以不用传密码
返回更新后的身份信息
NoPermission 不允许执行更新操作
const template = { extend: { name: 'New Name' } }const updatedIdentity = await identityManager.updateIdentity('example-did', template, 'example-password') Copy
const template = { extend: { name: 'New Name' } }const updatedIdentity = await identityManager.updateIdentity('example-did', template, 'example-password')
管理身份,支持身份的创建、登录、登出、更新和导入导出等操作