Account
The account module provides a series of methods related to Mystiko accounts.
Data Structure
An account is an object generated from protobuf with the following properties:
Property | Type | Description |
---|---|---|
id | string | The unique identifier of the account. |
createdAt | bigint | The timestamp when the account was created. |
updatedAt | bigint | The timestamp when the account was last updated. |
name | string | The name of the account. |
shieldedAddress | string | The shielded address of the account. |
publicKey | string | The public key of the account. |
encryptedSecretKey | string | The encrypted secret key of the account. |
walletId | string | The unique identifier of the wallet to which the account belongs. |
scannedToId | string | The unique identifier of the last scanned transaction. |
Create
Create an Account.
import mystiko from '@mystikonetwork/node';
const options = new core.handler.v1.CreateAccountOptions({
walletPassword: WalletPassword,
name: 'test_account',
});
const account = mystiko.account?.create(options);
The parameter list for CreateAccountOptions
:
Parameter | Required | Description |
---|---|---|
walletPassword | true | The password of the encrypted wallet. |
name | false | The name of the account. |
secretKey | false | The secret key of the account. |
Count
Query the number of accounts in the wallet based on specific conditions.
import mystiko from '@mystikonetwork/node';
import { storage } from '@mystikonetwork/protos';
const queryFilters = new storage.v1.SubFilter({
column: 'name',
values: [],
operator: storage.v1.SubFilterOperator.IS_NOT_NULL,
});
const total = mystiko.account?.count(queryFilters);
CountAll
Query the total number of accounts in the wallet.
import mystiko from '@mystikonetwork/node';
const total = mystiko.account?.count(undefined);
Find
Query accounts based on specific conditions.
import mystiko from '@mystikonetwork/node';
const filter = new storage.v1.SubFilter({
column: 'name',
values: ['test_account'],
operator: storage.v1.SubFilterOperator.IN,
});
const account = mystiko.account?.find(filter);
FindAll
Query all accounts in the wallet.
import mystiko from '@mystikonetwork/node';
const account = mystiko.account?.find(undefined);
FindById
Query an account by its unique identifier.
import mystiko from '@mystikonetwork/node';
const account = mystiko.account?.findById('accountId');
FindByShieldedAddress
Query an account by its shielded address.
import mystiko from '@mystikonetwork/node';
const account = mystiko.account?.findByShieldedAddress('shieldedAddress');
FindByPublicKey
Query an account by its public key.
import mystiko from '@mystikonetwork/node';
const account = mystiko.account?.findByPublicKey('publicKey');
Update
The parameter list for UpdateAccountOptions
:
Parameter | Required | Description |
---|---|---|
walletPassword | true | The password of the encrypted wallet. |
name | false | The name of the account. |
UpdateById
Update an account by its unique identifier.
import mystiko from '@mystikonetwork/node';
import { core } from '@mystikonetwork/protos';
const options = new core.handler.v1.UpdateAccountOptions({
walletPassword: "WalletPassword",
name: 'account1'
});
const account = mystiko.account?.updateById('accountId', options);
UpdateByShieldedAddress
Update an account by its shielded address.
import mystiko from '@mystikonetwork/node';
import { core } from '@mystikonetwork/protos';
const options = new core.handler.v1.UpdateAccountOptions({
walletPassword: "WalletPassword",
name: 'account1'
});
const account = mystiko.account?.updateByShieldedAddress('shieldedAddress', options);
UpdateByPublicKey
Update an account by its public key.
import mystiko from '@mystikonetwork/node';
import { core } from '@mystikonetwork/protos';
const options = new core.handler.v1.UpdateAccountOptions({
walletPassword: "WalletPassword",
name: 'account1'
});
const account = mystiko.account?.updateByPublicKey('publicKey', options);
UpdateEncryption
Update the encryption of an account.
import mystiko from '@mystikonetwork/node';
const account = mystiko.account?.updateEncryption(oldPassword, newPassword);
Export
ExportSecretKeyById
Export the secret key of an account by its unique identifier.
import mystiko from '@mystikonetwork/node';
const key = mystiko.account?.exportSecretKeyById('walletPassword', "accountId");
ExportSecretKeyByPublicKey
Export the secret key of an account by its public key.
import mystiko from '@mystikonetwork/node';
const key = mystiko.account?.exportSecretKeyByPublicKey('walletPassword', "publicKey");
ExportSecretKeyByShieldedAddress
Export the secret key of an account by its shielded address.
import mystiko from '@mystikonetwork/node';
const key = mystiko.account?.exportSecretKeyByShieldedAddress('walletPassword', "shieldedAddress");