Class: Account

Account


new Account(priv, path)

Account constructor. Class encapsulate main operation with account entity.
Parameters:
Name Type Description
priv Hash Account private key.
path String
Example
var account = new Account(new Buffer("ac3773e06ae74c0fa566b0e421d4e391333f31aef90b383f0c0e83e4873609d6", "hex") );

Methods


<static> NewAccount()

Account factory method. Create random account.
Returns:
Instance of Account constructor.
Type
Account
Example
var account = Account.NewAccount();

<static> isValidAddress(addr, type)

Address validation method.
Parameters:
Name Type Description
addr String/Hash Account address.
type Number NormalType / ContractType
Returns:
Is address has correct format.
Type
Boolean
Example
if ( Account.isValidAddress("n1QZMXSZtW7BUerroSms4axNfyBGyFGkrh5") ) {
    // some code
};

<static> fromAddress(addr)

Restore account from address. Receive addr or Account instance. If addr is Account instance return new Account instance with same PrivateKey.
Parameters:
Name Type Description
addr Hash | Object Client address or Account instance.
Returns:
Instance of Account restored from address.
Type
Account
Example
var account = Account.fromAddress("n1QZMXSZtW7BUerroSms4axNfyBGyFGkrh5");

<static> fromPubKey(publicKey)

Restore account from public key.
Parameters:
Name Type Description
publicKey String/Hash Public key.
Returns:
Instance of Account restored from address.
Type
Account
Example
var account = Account.fromPubKey("f18ec04019dd131bbcfada4020b001d547244d768f144ef947577ce53a13ad690eb43e4b02a8daa3c168045cd122c0685f083e1656756ba7982721322ebe4da7");

setPrivateKey(priv)

Private Key setter.
Parameters:
Name Type Description
priv Hash Account private key.
Example
account.setPrivateKey("ac3773e06ae74c0fa566b0e421d4e391333f31aef90b383f0c0e83e4873609d6");

getPrivateKey()

Private Key getter.
Returns:
Account private key.
Type
Buffer
Example
var privKey = account.getPrivateKey();
//<Buffer 5b ed 67 f9 9c b3 31 9e 0c 6f 6a 03 54 8b e3 c8 c5 2a 83 64 46 4f 88 6f> 24

getPrivateKeyString()

Get Private Key in hex string format.
Returns:
Account private key in String format.
Type
HexString
Example
var privKey = account.getPrivateKeyString();
//"ac3773e06ae74c0fa566b0e421d4e391333f31aef90b383f0c0e83e4873609d6"

getPublicKey()

Public Key getter.
Returns:
Account public key.
Type
Buffer
Example
var publicKey = account.getPublicKey();
//<Buffer c0 96 aa 4e 66 c7 4a 9a c7 18 31 f1 24 72 2a c1 3e b5 df 7f 97 1b 13 1d 46 a2 8a e6 81 c6 1d 96 f7 07 d0 aa e9 a7 67 436b 68 af a8 f0 96 65 17 24 29 ... >

getPublicKeyString()

Get Public Key in hex string format.
Returns:
Account public key in String format.
Type
HexString
Example
var publicKey = account.getPublicKey();
//"f18ec04019dd131bbcfada4020b001d547244d768f144ef947577ce53a13ad690eb43e4b02a8daa3c168045cd122c0685f083e1656756ba7982721322ebe4da7"

getAddress()

Accaunt address getter.
Returns:
Account address.
Type
Buffer
Example
var publicKey = account.getAddress();
//<Buffer 7f 87 83 58 46 96 12 7d 1a c0 57 1a 42 87 c6 25 36 08 ff 32 61 36 51 7c>

getAddressString()

Get account address in hex string format.
Returns:
Account address in String format.
Type
HexString
Example
var publicKey = account.getAddressString();
//"802d529bf55d6693b3ac72c59b4a7d159da53cae5a7bf99c"

toKey(password, opts)

Generate key buy passphrase and options.
Parameters:
Name Type Description
password Password Provided password.
opts KeyOptions Key options.
Returns:
Key Object.
Type
Key
Example
var key = account.toKey("passphrase");

toKeyString(password, opts)

Generate key buy passphrase and options. Return in JSON format.
Parameters:
Name Type Description
password Password Provided password.
opts KeyOptions Key options.
Returns:
JSON stringify Key.
Type
String
Example
var key = account.toKeyString("passphrase");

fromKey(input, password, nonStrict)

Restore account from key and passphrase.
Parameters:
Name Type Description
input Key Key Object.
password Password Provided password.
nonStrict Boolean Strict сase sensitivity flag.
Returns:
Account - Instance of Account restored from key and passphrase.