Skip to main content

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:

PropertyTypeDescription
idstring
The unique identifier of the account.
createdAtbigint
The timestamp when the account was created.
updatedAtbigint
The timestamp when the account was last updated.
namestring
The name of the account.
shieldedAddressstring
The shielded address of the account.
publicKeystring
The public key of the account.
encryptedSecretKeystring
The encrypted secret key of the account.
walletIdstring
The unique identifier of the wallet to which the account belongs.
scannedToIdstring
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:

ParameterRequiredDescription
walletPasswordtrue
The password of the encrypted wallet.
namefalse
The name of the account.
secretKeyfalse
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:

ParameterRequiredDescription
walletPasswordtrue
The password of the encrypted wallet.
namefalse
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");