]> git.codecow.com Git - libnemo.git/commitdiff
Deprecate remaining padStart usages.
authorChris Duncan <chris@codecow.com>
Fri, 3 Jul 2026 07:25:57 +0000 (00:25 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 3 Jul 2026 07:25:57 +0000 (00:25 -0700)
src/lib/crypto/blake2b.ts
src/lib/tools.ts
test/test.blake2b.mjs

index 18bfca7de60449f2b6635989aa9088345e7c8e2a..b7b3e6743c20ff8efb07bbbaf0afd41d9e0c3644 100644 (file)
@@ -248,9 +248,11 @@ export class Blake2b {
         *
         * @returns {Bytes}
         */
-       digest (): Bytes {
+       digest (): Bytes
+       digest (format: 'hex'): string
+       digest (format?: 'hex'): Bytes | string {
                const buf = new Uint8Array(this.#outlen)
                this.#blake2bFinal(buf)
-               return buf
+               return (format === 'hex') ? bytes.toHex(buf) : buf
        }
 }
index 52e1a9c2a633e8dccd45682e86d86220d72864f0..0f4f90b5f2a1705f192fa7c0cfd134f73acfcb90 100644 (file)
@@ -89,7 +89,8 @@ export class Tools {
 
                // convert to desired denomination
                const outUnit = UNITS[outputUnit]
-               i = int.toString().padStart(40, '0')
+               i = int.toString()
+               while (i.length < 40) i = '0' + i
                f = i.slice(40 - outUnit).replace(/0*$/g, '')
                i = i.slice(0, 40 - outUnit).replace(/^0*/g, '')
                const output = `${i === '' ? '0' : i}${f === '' ? '' : '.'}${f}`
index 08103817aa66cc054648a94b1874b37d1775e466..87ab22ff47df50bcd6190d1b4a5c43535b8e5089 100644 (file)
@@ -31,8 +31,8 @@ await Promise.all([
                                        )\r
                                }\r
                                try {\r
-                                       const output = new Blake2b(64, key).update(input).digest()\r
-                                       const hex = [...output].map(b => b.toString(16).padStart(2, '0')).join('')\r
+                                       /** @type {string} */\r
+                                       const hex = new Blake2b(64, key).update(input).digest('hex')\r
                                        assert.equal(hex, test.out)\r
                                } catch (err) {\r
                                        console.error(`blake2b reference test vector ${i} failed`, { cause: err })\r
@@ -83,9 +83,8 @@ await Promise.all([
                                        )\r
                                }\r
                                try {\r
-                                       /** @type {Uint8Array<ArrayBuffer>} */\r
-                                       const output = new Blake2b(test.outlen ?? 64, key, salt, personal).update(input).digest()\r
-                                       const hex = [...output].map(b => b.toString(16).padStart(2, '0')).join('')\r
+                                       /** @type {string} */\r
+                                       const hex = new Blake2b(test.outlen ?? 64, key, salt, personal).update(input).digest('hex')\r
                                        assert.equal(hex, test.out)\r
                                } catch (err) {\r
                                        console.error(`blake2b libsodium test vector ${i} failed`, { cause: err })\r