]> zoso.dev Git - libnemo.git/commitdiff
Create method to destroy entropy by randomizing its byte values.
authorChris Duncan <chris@zoso.dev>
Mon, 9 Dec 2024 13:48:30 +0000 (05:48 -0800)
committerChris Duncan <chris@zoso.dev>
Mon, 9 Dec 2024 13:48:30 +0000 (05:48 -0800)
src/lib/entropy.ts

index 295c8d32a1d6344dd4a67750159ebc3f9c851248..3fb5cbaba3400167b8e95fda49161f1b6e2dba6d 100644 (file)
@@ -117,4 +117,16 @@ export class Entropy {
                        reject(new TypeError(`Entropy cannot import ${typeof input}`))
                })
        }
+
+       /**
+       * Randomizes the bytes, rendering the original values generally inaccessible.
+       */
+       destroy (): boolean {
+               try {
+                       crypto.getRandomValues(this.#bytes)
+                       return true
+               } catch (err) {
+                       return false
+               }
+       }
 }