From: Chris Duncan Date: Thu, 10 Oct 2024 22:10:12 +0000 (-0700) Subject: Sanitize rolodex entry names and validate it and address as strings. X-Git-Tag: v0.0.7~4 X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=ee5bd8236750cdcb6a5e70323ac9e5de82059137;p=libnemo.git Sanitize rolodex entry names and validate it and address as strings. --- 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.