welsonjs/lib/totp.js

52 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2024-11-25 16:41:21 +00:00
// totp.js
// TOTP library for WelsonJS framework
// Namhyeon Go <abuse@catswords.net>
// https://github.com/gnh1201/welsonjs
//
// ***SECURITY NOTICE***
// The TOTP library requires an internet connection, and data may be transmitted externally. Users must adhere to the terms of use and privacy policy.
// - Privacy Policy: https://policy.catswords.social/site_terms.html
// - Terms of Service: https://policy.catswords.social/site_extended_description.html
//
var JsonRpc2 = require("lib/jsonrpc2");
2024-11-25 17:46:06 +00:00
var API_URL = "https://public-api.catswords.net";
2024-11-25 16:41:21 +00:00
function getPubKey() {
2024-11-25 17:46:06 +00:00
var rpc = JsonRpc2.create(API_URL);
2024-11-25 16:42:39 +00:00
var result = rpc.invoke("relay_invoke_method", {
2024-11-25 16:49:36 +00:00
"callback": "load_script",
2024-11-25 16:42:39 +00:00
"requires": [
"https://raw.githubusercontent.com/dimamedia/PHP-Simple-TOTP-and-PubKey/refs/heads/master/class.tfa.php"
],
"args": [
"$tfa = new tfa(); return $tfa->getPubKey()"
]
}, "");
return result.data;
2024-11-25 16:41:21 +00:00
}
2024-11-25 17:03:15 +00:00
function getOtp(pubkey) {
2024-11-25 17:46:06 +00:00
var rpc = JsonRpc2.create(API_URL);
2024-11-25 16:42:39 +00:00
var result = rpc.invoke("relay_invoke_method", {
2024-11-25 16:49:36 +00:00
"callback": "load_script",
2024-11-25 16:42:39 +00:00
"requires": [
"https://raw.githubusercontent.com/dimamedia/PHP-Simple-TOTP-and-PubKey/refs/heads/master/class.tfa.php"
],
"args": [
2024-11-25 17:03:15 +00:00
"$tfa = new tfa(); return $tfa->getOtp('" + pubkey + "')"
2024-11-25 16:42:39 +00:00
]
}, "");
2024-11-25 16:41:21 +00:00
2024-11-25 16:42:39 +00:00
return result.data;
2024-11-25 16:41:21 +00:00
}
exports.getPubKey = getPubKey;
exports.getOtp = getOtp;
2024-11-25 16:42:39 +00:00
2024-11-25 17:46:06 +00:00
exports.VERSIONINFO = "TOTP library (totp.js) version 0.1.3";
2024-11-25 16:42:39 +00:00
exports.AUTHOR = "abuse@catswords.net";
exports.global = global;
exports.require = global.require;