From cf9d83f0515b0b1bfe3a2650b4c358a215135837 Mon Sep 17 00:00:00 2001 From: Juri Gavshin <51777744+bolt-juri-gavshin@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:14:38 +0200 Subject: [PATCH] Fix jsbn browser check Previous versions of NodeJS/Bun/Deno didn't have 'navigator' defined, while latest one do have it, which forces am2 algorithm with 26 dbits, which is awfully slow, at least in NodeJS v22 (compared to am3 with 28 bits) --- lib/jsbn.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jsbn.js b/lib/jsbn.js index 11f965c56..80f1a27a3 100644 --- a/lib/jsbn.js +++ b/lib/jsbn.js @@ -116,8 +116,8 @@ function am3(i,x,w,j,c,n) { return c; } -// node.js (no browser) -if(typeof(navigator) === 'undefined') +// node.js/bun/deno (no browser), latest versions have 'navigator' defined, but 'navigator.appName' is still undefined +if(typeof(navigator) === 'undefined' || typeof(navigator.appName) === 'undefined') { BigInteger.prototype.am = am3; dbits = 28;