-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_uri.ts
53 lines (43 loc) · 1.38 KB
/
generate_uri.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import * as fs from 'fs';
import * as path from 'path';
interface Account {
accountID: string;
originalUserName?: string;
userName?: string;
originalIssuerName?: string;
issuerName?: string;
isFavorite?: boolean;
secret: string;
algorithm?: string;
digits?: number;
timeStep?: number;
}
interface InputData {
accounts?: Account[];
}
function main(): void {
const inputFile: string = path.join(process.cwd(), 'lastpass.json');
const inputData: InputData = JSON.parse(fs.readFileSync(inputFile, 'utf-8'));
const outputData: string[] = [];
inputData.accounts?.forEach((account: Account) => {
let {
userName,
originalUserName,
originalIssuerName,
issuerName,
secret,
algorithm = 'SHA1',
digits = 6,
timeStep = 30,
} = account;
const encodedName = encodeURIComponent(userName ?? originalUserName ?? 'UnknownUser');
const encodedIssuer = encodeURIComponent(issuerName ?? originalIssuerName ?? 'UnknownIssuer');
secret = secret.replace(/\s/g, '');
const url = `otpauth://totp/${encodedIssuer}:${encodedName}?secret=${secret}&algorithm=${algorithm}&digits=${digits}&period=${timeStep}`;
outputData.push(url);
});
const outputFile: string = path.join(process.cwd(), 'uris.txt');
fs.writeFileSync(outputFile, outputData.join('\n'));
console.log(`Converted. Export file: ${outputFile}`);
}
main();