]> zoso.dev Git - libnemo.git/commitdiff
Add try-catch block to avoid esbuild warnings when building for browser.
authorChris Duncan <chris@zoso.dev>
Tue, 26 Nov 2024 05:46:54 +0000 (21:46 -0800)
committerChris Duncan <chris@zoso.dev>
Tue, 26 Nov 2024 05:46:54 +0000 (21:46 -0800)
src/lib/workers/nacl-nano.ts

index 7bac2400c54021029e214cb88f8fd7bd40df7941..f800f94bb0be04fe9312f246c9a02498c866e6c4 100644 (file)
@@ -866,13 +866,17 @@ const setPRNG = function(fn) {
                });\r
        } else if (typeof require !== 'undefined') {\r
                // Node.js.\r
-               crypto = require('crypto');\r
-               if (crypto && crypto.randomBytes) {\r
-                       setPRNG(function(x, n) {\r
-                               var i, v = crypto.randomBytes(n);\r
-                               for (i = 0; i < n; i++) x[i] = v[i];\r
-                               cleanup(v);\r
-                       });\r
+               try {\r
+                       crypto = require('node:crypto');\r
+                       if (crypto && crypto.randomBytes) {\r
+                               setPRNG(function(x, n) {\r
+                                       var i, v = crypto.randomBytes(n);\r
+                                       for (i = 0; i < n; i++) x[i] = v[i];\r
+                                       cleanup(v);\r
+                               });\r
+                       }\r
+               } catch (err) {\r
+                       throw new Error('failed to load node:crypto')\r
                }\r
        }\r
 })();\r