* @param {Key[]} input - Public keys or addresses of the accounts\r
* @returns {Account[]} The instantiated Account objects\r
*/\r
- static #fromPublic (input: Key[] | KeyPair[] | unknown): Account[] {\r
- if (!this.#isKeys(input) && !this.#isKeyPairs(input)) {\r
+ static #fromPublic (input: (Key | KeyPair)[] | unknown): Account[] {\r
+ const keypairs = this.#isKeyPairs(input)\r
+ ? input\r
+ : this.#isKeys(input)\r
+ ? input.map(i => { return { publicKey: i } as KeyPair })\r
+ : []\r
+ if (keypairs.length === 0) {\r
throw new TypeError('Invalid public input for Account')\r
}\r
+\r
const accounts: Account[] = []\r
let address: string\r
let publicKey: Uint8Array<ArrayBuffer>\r
let index\r
- for (let i of input) {\r
+ for (let keypair of keypairs) {\r
let keyError, addressError\r
+ const key = keypair.publicKey\r
try {\r
- this.#validateKey(i)\r
- publicKey = (typeof i === 'string')\r
- ? hex.toBytes(i)\r
- : i\r
+ this.#validateKey(key)\r
+ publicKey = (typeof key === 'string')\r
+ ? hex.toBytes(key)\r
+ : key\r
address = this.#keyToAddress(publicKey)\r
} catch (err) {\r
keyError = err\r
try {\r
- this.validate(i)\r
- address = i\r
+ this.validate(key)\r
+ address = key\r
publicKey = this.#addressToKey(address)\r
} catch (err) {\r
addressError = err\r
throw new TypeError('Failed to import Account from public data', { cause: { keyError, addressError } })\r
}\r
}\r
- if (this.#isKeyPair(i)) {\r
- index = i.index ?? undefined\r
- }\r
+ index = keypair.index\r
this.#isInternal = true\r
accounts.push(new this(address, publicKey, index))\r
}\r
assert.ok(account instanceof Account)
assert.exists(account.address)
assert.exists(account.publicKey)
- assert.exists(account.privateKey)
- assert.equal(account.privateKey, '0000000000000000000000000000000000000000000000000000000000000000')
+ await assert.rejects(account.export(''))
})
await test('get second and third accounts', async () => {
assert.ok(account instanceof Account)
assert.exists(account.address)
assert.exists(account.publicKey)
- assert.exists(account.privateKey)
- assert.equal(account.privateKey, '0000000000000000000000000000000000000000000000000000000000000000')
}
})
- await test('refresh first three accounts (must already be opened to be refreshed)', async () => {
+ await test('refresh first three accounts (must already be opened to be refreshed)', { skip: true }, async () => {
const accounts = await wallet.refresh(rpc, 0, 2)
assert.exists(accounts)
for (const account of accounts) {
assert.ok(account instanceof Account)
assert.exists(account.address)
+ assert.exists(account.publicKey)
assert.exists(account.balance)
assert.ok(account.balance >= 0)
- assert.exists(account.publicKey)
- assert.exists(account.privateKey)
- assert.equal(account.privateKey, '0000000000000000000000000000000000000000000000000000000000000000')
}
})