@zcloak/wallet-lib v0.1.4
wallet-lib
This is a web wallet developed based on zkid-sdk, which supports use in Chrome extension and web pages.
Get Start
await utils.initCrypto();
const didAccounts = new DidAccounts();
await didAccounts.isReady;DidAccounts
Manages a collection of DID accounts and provides operations for account management.
public async generate(mnemonic: string, passphrase: string, alias?: string): Promise<DidAccount>
Generates a new DID account from a mnemonic.
- mnemonic: The mnemonic for generating the account.
- passphrase: The passphrase to secure the account.
- alias(optional): An alias for the generated account.
public async unlock(passphrase: string)
Unlocks the wallet with a passphrase.
- passphrase: The passphrase used to unlock the wallet.
public async importDidFile(json: DidKeys$Json, password: string, alias?: string): Promise<DidAccount>
Imports a DID account from a JSON representation.
- json: The JSON representation of the account.
- password: The password to decrypt the account.
- alias(optional): An alias for the imported account.
public exportDidFile(id: DidUrl): DidKeys$Json
Exports a DID account as a JSON representation.
- id: The DID URL of the account to export.
private async addAccount(account: DidAccount)
Adds a DidAccount instance to the collection and updates related data.
- account: The- DidAccountinstance to add.
public async removeAccount(id: DidUrl): Promise<void>
Removes a DID account from the collection and related data.
- id: The DID URL of the account to remove.
get current(): DidAccount | null
Returns the currently selected DidAccount instance or null if no account is selected.
get accounts(): DidAccount[]
Returns an array of all DidAccount instances in the collection.
WalletKeyring
WalletKeyring is a specialized keyring for managing key pairs, providing wallet-specific functionality. You can override it if you need.
store
Used @zcloak/ui-store
browser
- BrowserStore
- BrowserSession
extension
- ExtensionSession
- ExtensionStore
Utility Functions
mnemonicGenerate
Creates a valid mnemonic string using using BIP39.
mnemonicValidate
Validates a mnemonic input using BIP39.
isPairKey(key: string): key is string
Checks if a given string key is a key pair identifier key.
- key: The string key to check.
- Returns trueif the key is a key pair identifier key,falseotherwise.
isDidKey(key: string): key is string
Checks if a given string key is a DID (Decentralized Identifier) identifier key.
- key: The string key to check.
- Returns trueif the key is a DID identifier key,falseotherwise.
DidAccount
The DidAccount class represents a DID (Decentralized Identifier) account and provides methods for managing the account and associated metadata.
constructor(did: Did, store: BaseStore)
- did: The- Didinstance associated with the account.
- store: A- BaseStoreinstance for data storage.
Properties
isReady: Promise<this>
- A promise that resolves when the DidAccountinstance is ready for use.
Methods
public async storeMeta(meta: DidAccountMeta)
Stores metadata associated with the account.
- meta: Metadata to store for the account.
public async storeDocument()
Stores the document associated with the account.
public async remove(): Promise<void>
Removes the account and associated metadata from storage.
Getters
instance: Did
- Returns the Didinstance associated with the account.
metaKey
- Returns the key used to store metadata associated with the account.
meta: DidAccountMeta
- Returns the metadata associated with the account.
License
This project is open source and available under the MIT License.