if (v instanceof Account) {\r
this.#representative = v\r
} else if (typeof v === 'string') {\r
- this.#representative = Account.import(v)\r
+ this.#representative = Account.load(v)\r
} else {\r
throw new TypeError(`Invalid argument for account representative: ${v}`)\r
}\r
* @param {string} address - Address of the account\r
* @returns {Account} A new Account object\r
*/\r
- static import (address: string): Account\r
+ static load (address: string): Account\r
/**\r
* Instantiates Account objects from their Nano addresses.\r
*\r
* @param {string[]} addresses - Addresses of the accounts\r
* @returns {Account[]} Array of new Account objects\r
*/\r
- static import (addresses: string[]): Account[]\r
+ static load (addresses: string[]): Account[]\r
/**\r
* Instantiates an Account object from its public key. It is unable to sign\r
* blocks or messages since it has no private key.\r
* @param {Key} publicKey - Public key of the account\r
* @returns {Account} A new Account object\r
*/\r
- static import (publicKey: Key): Account\r
+ static load (publicKey: Key): Account\r
/**\r
* Instantiates Account objects from their public keys. They are unable to sign\r
* blocks or messages since they have no private key.\r
* @param {Key[]} publicKeys - Public keys of the accounts\r
* @returns {Account[]} Array of new Account objects\r
*/\r
- static import (publicKeys: Key[]): Account[]\r
+ static load (publicKeys: Key[]): Account[]\r
/**\r
* Instantiates an Account object from its public key. It is unable to sign\r
* blocks or messages since it has no private key.\r
* @param {KeyPair} keypair - Index and keys of the account\r
* @returns {Account} A new Account object\r
*/\r
- static import (keypair: KeyPair): Account\r
+ static load (keypair: KeyPair): Account\r
/**\r
* Instantiates Account objects from their public keys. They are unable to sign\r
* blocks or messages since they have no private key.\r
* @param {KeyPair[]} keypairs - Indexes and keys of the accounts\r
* @returns {Account[]} Array of new Account objects\r
*/\r
- static import (keypairs: KeyPair[]): Account[]\r
+ static load (keypairs: KeyPair[]): Account[]\r
/**\r
* Instantiates an Account object from its private key which is used to derive\r
* a public key and then discarded.\r
* @param {string} type - Indicates a private key\r
* @returns {Promise<Account>} Promise for a new Account object\r
*/\r
- static async import (keypair: KeyPair, type: 'private'): Promise<Account>\r
+ static async load (keypair: KeyPair, type: 'private'): Promise<Account>\r
/**\r
* Instantiates Account objects from their private keys which are used to\r
* derive public keys and then discarded.\r
* @param {string} type - Indicates private keys\r
* @returns {Promise<Account[]>} Promise for array of new Account objects\r
*/\r
- static async import (keypairs: KeyPair[], type: 'private'): Promise<Account[]>\r
- static import (input: Key | KeyPair | (Key | KeyPair)[], type?: 'private'): Account | Account[] | Promise<Account | Account[]> {\r
+ static async load (keypairs: KeyPair[], type: 'private'): Promise<Account[]>\r
+ static load (input: Key | KeyPair | (Key | KeyPair)[], type?: 'private'): Account | Account[] | Promise<Account | Account[]> {\r
const isInputArray = Array.isArray(input)\r
const inputs = isInputArray ? input : [input]\r
if (this.#isKeyPairs(inputs) && type === 'private') {\r
this.#balance = BigInt(balance)\r
this.#frontier = frontier\r
this.#receivable = BigInt(receivable)\r
- this.#representative = await Account.import(representative)\r
+ this.#representative = await Account.load(representative)\r
this.#weight = BigInt(weight)\r
}\r
\r
constructor (account: unknown, balance: unknown, previous: unknown, representative: unknown) {
try {
if (typeof account === 'string') {
- account = Account.import(account)
+ account = Account.load(account)
}
if (typeof representative === 'string') {
- representative = Account.import(representative)
+ representative = Account.load(representative)
}
if (!(account instanceof Account)) {
throw new TypeError('Invalid account')
throw new TypeError('Invalid account')
}
this.representative = (typeof representative === 'string')
- ? Account.import(representative)
+ ? Account.load(representative)
: representative
this.link = hex.toBytes(BURN_PUBLIC_KEY)
throw new TypeError('Invalid account')
}
this.link = (typeof account === 'string')
- ? hex.toBytes(Account.import(account).publicKey)
+ ? hex.toBytes(Account.load(account).publicKey)
: hex.toBytes(account.publicKey)
return this
.replaceAll('<', '\\u003c')
.replaceAll('>', '\\u003e')
.replaceAll('\\', '\\u005c')
- const account = Account.import(address)
+ const account = Account.load(address)
try {
const existingName = await this.getName(account.address)
static async verify (name: string, signature: string, ...data: string[]): Promise<boolean> {
const addresses = await this.getAddresses(name)
for (const address of addresses) {
- const { publicKey } = Account.import(address)
+ const { publicKey } = Account.load(address)
const verified = await verify(publicKey, signature, ...data)
if (verified) {
return true
const blockQueue: Promise<void>[] = []
const results: { status: 'success' | 'error', address: string, message: string }[] = []
- const recipientAccount = Account.import(recipient)
+ const recipientAccount = Account.load(recipient)
const accounts = await wallet.refresh(rpc, from, to)
for (const account of accounts) {
if (account.representative?.address && account.frontier && account.index) {
}\r
const publicKeys: KeyPair[] = await Promise.all(promises)\r
if (publicKeys.length > 0) {\r
- const publicAccounts = Account.import(publicKeys)\r
+ const publicAccounts = Account.load(publicKeys)\r
for (const a of publicAccounts) {\r
if (a.index == null) {\r
throw new RangeError('Index missing for Account')\r
for (const key of Object.keys(errors ?? {})) {\r
const value = errors[key]\r
if (value === 'Account not found') {\r
- return Account.import(key)\r
+ return Account.load(key)\r
}\r
}\r
return await this.unopened(rpc, batchSize, from + batchSize)\r
if (status !== 'OK' || publicKey == null) {\r
throw new Error(`Error getting Ledger account: ${status}`)\r
}\r
- return Account.import({ index, publicKey })\r
+ return Account.load({ index, publicKey })\r
}\r
\r
/**\r
* @param {string} address - Address of the account
* @returns {Account} A new Account object
*/
- static import (address: string): Account
+ static load (address: string): Account
/**
* Instantiates Account objects from their Nano addresses.
*
* @param {string[]} addresses - Addresses of the accounts
* @returns {Account[]} Array of new Account objects
*/
- static import (addresses: string[]): Account[]
+ static load (addresses: string[]): Account[]
/**
* Instantiates an Account object from its public key. It is unable to sign
* blocks or messages since it has no private key.
* @param {Key} publicKey - Public key of the account
* @returns {Account} A new Account object
*/
- static import (publicKey: Key): Account
+ static load (publicKey: Key): Account
/**
* Instantiates Account objects from their public keys. They are unable to sign
* blocks or messages since they have no private key.
* @param {Key[]} publicKeys - Public keys of the accounts
* @returns {Account[]} Array of new Account objects
*/
- static import (publicKeys: Key[]): Account[]
+ static load (publicKeys: Key[]): Account[]
/**
* Instantiates an Account object from its public key. It is unable to sign
* blocks or messages since it has no private key.
* @param {KeyPair} keypair - Index and keys of the account
* @returns {Account} A new Account object
*/
- static import (keypair: KeyPair): Account
+ static load (keypair: KeyPair): Account
/**
* Instantiates Account objects from their public keys. They are unable to sign
* blocks or messages since they have no private key.
* @param {KeyPair[]} keypairs - Indexes and keys of the accounts
* @returns {Account[]} Array of new Account objects
*/
- static import (keypairs: KeyPair[]): Account[]
+ static load (keypairs: KeyPair[]): Account[]
/**
* Instantiates an Account object from its private key which is used to derive
* a public key and then discarded.
* @param {string} type - Indicates a private key
* @returns {Promise<Account>} Promise for a new Account object
*/
- static import (keypair: KeyPair, type: 'private'): Promise<Account>
+ static load (keypair: KeyPair, type: 'private'): Promise<Account>
/**
* Instantiates Account objects from their private keys which are used to
* derive public keys and then discarded.
* @param {string} type - Indicates private keys
* @returns {Promise<Account[]>} Promise for array of new Account objects
*/
- static import (keypairs: KeyPair[], type: 'private'): Promise<Account[]>
+ static load (keypairs: KeyPair[], type: 'private'): Promise<Account[]>
/**
* Refreshes the account from its current state on the network.
*
.sign(wallet, account.index)\r
assert.ok(await sendBlock.verify(account.publicKey))\r
\r
- const wrongAccount = Account.import('nano_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p')\r
+ const wrongAccount = Account.load('nano_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p')\r
assert.equal(await sendBlock.verify(wrongAccount.publicKey), false)\r
\r
await assert.resolves(wallet.destroy())\r