Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function makeQR(secret) {
secret32 = base32.stringify(base64.parse(secret))
secret32 = secret32.replace(/=+$/, "")
totp_uri = 'otpauth://totp/myGov?secret=' + secret32 + '&algorithm=SHA512'
qrcode.toDataURL(totp_uri)
.then(url => {
setStatus("Enroll this secret in your TOTP client and enter the current code");
setDetail(totp_uri + '<p><img src="' + url + '">');
showCodeForm(true);
})
.catch(err => {
setError("QR encoding error", err);
})
}
</p>
enableOtp (otpTimeout: number) {
const { ai } = this
const login = this.loginTree
checkLogin(login)
const otpKey =
login.otpKey != null
? fixOtpKey(login.otpKey)
: base32.stringify(ai.props.io.random(10))
const kit = {
serverPath: '/v2/login/otp',
server: {
otpKey,
otpTimeout
},
stash: {
otpKey,
otpResetDate: void 0,
otpTimeout
},
login: {
otpKey,
otpResetDate: void 0,
otpTimeout
async getIndexTypeColumn(tableName, fieldName, indexName)
{
let hash = await Util.hmac(
'sha384',
Util.pack([
await Util.toBuffer(fieldName),
await Util.toBuffer(indexName)
]),
tableName,
true
);
return base32.stringify(hash.slice(0, 8))
.toLowerCase()
.replace(/=+$/, '');
}
async getIndexTypeColumn(tableName, fieldName, indexName)
{
if (!sodium) sodium = await SodiumPlus.auto();
tableName = await Util.toBuffer(tableName);
fieldName = await Util.toBuffer(fieldName);
indexName = await Util.toBuffer(indexName);
let hash = await sodium.crypto_generichash(tableName, null, 16);
let shorthash = await sodium.crypto_shorthash(
Util.pack([fieldName, indexName]),
new CryptographyKey(hash)
);
return base32.stringify(shorthash)
.toLowerCase()
.replace(/=+$/, '');
}
export async function enableOtp(
ai: ApiInput,
accountId: string,
otpTimeout: number
) {
const { loginTree } = ai.props.state.accounts[accountId]
const otpKey =
loginTree.otpKey != null
? fixOtpKey(loginTree.otpKey)
: base32.stringify(ai.props.io.random(10))
const kit: LoginKit = {
serverPath: '/v2/login/otp',
server: {
otpKey,
otpTimeout
},
stash: {
otpKey,
otpResetDate: void 0,
otpTimeout
},
login: {
otpKey,
otpResetDate: void 0,
otpTimeout