feat: changed TOTP and base32 library to self-writed special for quick-js, fixed BigInt incompatibility
This commit is contained in:
26
lib/totp-quickjs/base32decoder.js
Normal file
26
lib/totp-quickjs/base32decoder.js
Normal file
@@ -0,0 +1,26 @@
|
||||
export function decode(base32) {
|
||||
for (
|
||||
var base32chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
||||
bits = "",
|
||||
hex = "",
|
||||
i = 0;
|
||||
i < base32.length;
|
||||
i++
|
||||
) {
|
||||
var val = base32chars.indexOf(base32.charAt(i).toUpperCase());
|
||||
bits += leftpad(val.toString(2), 5, "0");
|
||||
}
|
||||
for (i = 0; i + 4 <= bits.length; i += 4) {
|
||||
var chunk = bits.substr(i, 4);
|
||||
hex += parseInt(chunk, 2).toString(16);
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
|
||||
function leftpad(str, len, pad) {
|
||||
return (
|
||||
len + 1 >= str.length &&
|
||||
(str = new Array(len + 1 - str.length).join(pad) + str),
|
||||
str
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user