From ee5bd8236750cdcb6a5e70323ac9e5de82059137 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 10 Oct 2024 15:10:12 -0700 Subject: [PATCH] Sanitize rolodex entry names and validate it and address as strings. --- src/lib/rolodex.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/lib/rolodex.ts b/src/lib/rolodex.ts index 3efffe5..2ebb7b9 100644 --- a/src/lib/rolodex.ts +++ b/src/lib/rolodex.ts @@ -29,9 +29,20 @@ export class Rolodex { if (name == null || name === '') { throw new Error('Name is required for rolodex entries') } + if (typeof name !== 'string') { + throw new Error('Name must be a string for rolodex entries') + } if (address == null || address === '') { - throw new Error('address is required for rolodex entries') + throw new Error('Address is required for rolodex entries') + } + if (typeof address !== 'string') { + throw new Error('Address must be a string for rolodex entries') } + name = name + .replaceAll('/', '\\u002f') + .replaceAll('<', '\\u003c') + .replaceAll('>', '\\u003d') + .replaceAll('\\', '\\u005c') const account = new Account(address) const nameResult = this.#entries.find(e => e.name === name) const accountResult = this.#entries.find(e => e.account.address === address) @@ -54,7 +65,7 @@ export class Rolodex { } /** - * Gets all Nano addresses associated with a name from the rolodex. + * Gets all names associated with a name from the rolodex. * * @param {string} name - Alias to look up * @returns {string[]} List of Nano addresses associated with the name @@ -64,6 +75,15 @@ export class Rolodex { return entries.map(a => a.account.address) } + /** + * Gets all names stored in the rolodex. + * + * @returns {string[]} List of names stored in the rolodex + */ + getAllNames (): string[] { + return this.#entries.map(e => e.name) + } + /** * Verifies whether the public key of any Nano address saved under a specific * name in the rolodex was used to sign a specific set of data. -- 2.34.1