* Instantiates an Account object from its private key. The corresponding\r
* public key will automatically be derived and saved.\r
*\r
- * @param {string} privateKey - Private key of the account\r
+ * @param {(string|Uint8Array)} privateKey - Private key of the account\r
* @param {number} [index] - Account number used when deriving the key\r
* @returns {Account} A new Account object\r
*/\r
* @returns True if successfully locked\r
*/\r
async lock (password: string | Uint8Array): Promise<boolean> {\r
- if (typeof password === 'string') {\r
- password = utf8.toBytes(password)\r
- }\r
- if (password == null || password.constructor.name !== 'Uint8Array') {\r
+ if (typeof password === 'string') password = utf8.toBytes(password)\r
+ if (password == null || !(password instanceof Uint8Array)) {\r
throw new Error('Failed to lock account')\r
}\r
try {\r
* @returns True if successfully unlocked\r
*/\r
async unlock (password: string | Uint8Array): Promise<boolean> {\r
- if (typeof password === 'string') {\r
- password = utf8.toBytes(password)\r
- }\r
- if (password == null || password.constructor.name !== 'Uint8Array') {\r
+ if (typeof password === 'string') password = utf8.toBytes(password)\r
+ if (password == null || !(password instanceof Uint8Array)) {\r
throw new Error('Failed to unlock account')\r
}\r
try {\r
* @param {string} address - Nano address to validate\r
* @throws Error if address is undefined, not a string, or an invalid format\r
*/\r
- static validate (address: string): void {\r
+ static validate (address: unknown): asserts address is string {\r
if (address === undefined) {\r
throw new ReferenceError('Address is undefined.')\r
}\r
if (typeof address !== 'string') {\r
throw new TypeError('Address must be a string.')\r
}\r
- const pattern = new RegExp(`^(${PREFIX}|${PREFIX_LEGACY})[13]{1}[${ALPHABET}]{59}$`,\r
- )\r
+ const pattern = new RegExp(`^(${PREFIX}|${PREFIX_LEGACY})[13]{1}[${ALPHABET}]{59}$`)\r
if (!pattern.test(address)) {\r
throw new RangeError('Invalid address format')\r
}\r