commit
73ea81af54
1
.prettierrc.yaml
Normal file
1
.prettierrc.yaml
Normal file
@ -0,0 +1 @@
|
||||
tabWidth: 4
|
@ -6,11 +6,12 @@ AppSideService(
|
||||
onInit(){
|
||||
|
||||
},
|
||||
onRequest(req, res){
|
||||
if(req.method === 'totps'){
|
||||
res(null, settings.settingsStorage.getItem('TOTPs'))
|
||||
}
|
||||
onRequest(request, response){
|
||||
if(request.method === 'totps'){
|
||||
response(null, settings.settingsStorage.getItem('TOTPs'))
|
||||
}
|
||||
},
|
||||
onSettingsChange(){ }
|
||||
}
|
||||
)
|
||||
)
|
15
app.js
15
app.js
@ -1,14 +1,11 @@
|
||||
import { BaseApp } from "@zeppos/zml/base-app"
|
||||
import { BaseApp } from "@zeppos/zml/base-app";
|
||||
|
||||
App(
|
||||
BaseApp(
|
||||
{
|
||||
BaseApp({
|
||||
globalData: {
|
||||
TOTPS: []
|
||||
TOTPS: [],
|
||||
},
|
||||
onCreate() {
|
||||
},
|
||||
onDestroy() {
|
||||
}
|
||||
onCreate() {},
|
||||
onDestroy() {},
|
||||
})
|
||||
)
|
||||
);
|
||||
|
5
app.json
5
app.json
@ -6,15 +6,14 @@
|
||||
"appType": "app",
|
||||
"version": {
|
||||
"code": 1,
|
||||
"name": "1.0.0"
|
||||
"name": "1.0.1"
|
||||
},
|
||||
"icon": "icon.png",
|
||||
"vender": "zepp",
|
||||
"description": "TOTP Authenticator for Amazfit devices"
|
||||
},
|
||||
"permissions": [
|
||||
"data:os.device.info",
|
||||
"device:os.local_storage"
|
||||
"data:os.device.info"
|
||||
],
|
||||
"runtime": {
|
||||
"apiVersion": {
|
||||
|
@ -16,7 +16,6 @@ export function getHOTP(counter, secret, digits = 6, hashType = 'SHA-1'){
|
||||
rawDataCounter.setUint32(4, counter)
|
||||
|
||||
const bCounter = new Uint8Array(rawDataCounter.buffer)
|
||||
console.log(bCounter)
|
||||
const bSecret = new Uint8Array(decode(secret).match(/.{1,2}/g).map(chunk => parseInt(chunk, 16))); //confirmed
|
||||
|
||||
//Stage 2: Hash data
|
||||
|
@ -1,37 +1,32 @@
|
||||
import { RenderAddButton } from './render/totpRenderer'
|
||||
import { initLoop } from './render/index/renderer'
|
||||
import { BasePage } from '@zeppos/zml/base-page'
|
||||
import { LocalStorage } from "@zos/storage"
|
||||
import { RenderAddButton } from "./render/totpRenderer";
|
||||
import { initLoop } from "./render/index/renderer";
|
||||
import { BasePage } from "@zeppos/zml/base-page";
|
||||
|
||||
const localStorage = new LocalStorage()
|
||||
const app = getApp()
|
||||
const app = getApp();
|
||||
let waitForFetch = true;
|
||||
Page(
|
||||
BasePage({
|
||||
onInit() {
|
||||
this.getTOTPData().then((x) => {
|
||||
console.log(x)
|
||||
localStorage.setItem('TOTPs', x ?? [])
|
||||
app._options.globalData.TOTPS = x ?? []
|
||||
this.getTOTPData()
|
||||
.then((x) => {
|
||||
app._options.globalData.TOTPS = JSON.parse(x) ?? [];
|
||||
this.initPage();
|
||||
})
|
||||
.catch(() => {
|
||||
app._options.globalData.TOTPS = localStorage.getItem('TOTPs') ?? []
|
||||
this.initPage()
|
||||
})
|
||||
.catch((x) => {
|
||||
app._options.globalData.TOTPS = [];
|
||||
this.initPage();
|
||||
});
|
||||
},
|
||||
build() {
|
||||
let fetch = setInterval(() => {
|
||||
if(waitForFetch)
|
||||
return;
|
||||
if (waitForFetch) return;
|
||||
|
||||
clearInterval(fetch);
|
||||
const buffer = app._options.globalData.TOTPS
|
||||
const buffer = app._options.globalData.TOTPS;
|
||||
if (buffer.length < 1) {
|
||||
RenderAddButton('page/tip')
|
||||
}
|
||||
else {
|
||||
initLoop(buffer)
|
||||
RenderAddButton("page/tip");
|
||||
} else {
|
||||
initLoop(buffer);
|
||||
}
|
||||
}, 100);
|
||||
},
|
||||
@ -40,8 +35,8 @@ Page(
|
||||
},
|
||||
getTOTPData() {
|
||||
return this.request({
|
||||
method: 'totps'
|
||||
method: "totps",
|
||||
});
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
|
@ -3,4 +3,4 @@ import { px } from "@zos/utils";
|
||||
export const TEXT_STYLE = {
|
||||
x: px(0),
|
||||
y: px(0),
|
||||
}
|
||||
};
|
||||
|
@ -1,46 +1,57 @@
|
||||
import { prop } from "@zos/ui";
|
||||
import { TOTP } from "../../../lib/totp-quickjs";
|
||||
import { RenderExpireBar, RenderOTPValue, RenderTOTPContainer } from '../totpRenderer'
|
||||
import {
|
||||
RenderExpireBar,
|
||||
RenderOTPValue,
|
||||
RenderTOTPContainer,
|
||||
} from "../totpRenderer";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Array<TOTP>} buffer
|
||||
*/
|
||||
export function initLoop(buffer) {
|
||||
renderContainers(buffer)
|
||||
renderTOTPs(buffer)
|
||||
renderContainers(buffer);
|
||||
renderTOTPs(buffer);
|
||||
}
|
||||
|
||||
function renderContainers(buffer) {
|
||||
for (let i = 0; i < buffer.length; i++) {
|
||||
RenderTOTPContainer(i, buffer[i].issuer, buffer[i].client)
|
||||
RenderTOTPContainer(i, buffer[i].issuer, buffer[i].client);
|
||||
}
|
||||
}
|
||||
const renderData = []
|
||||
const renderData = [];
|
||||
|
||||
function renderTOTPs(buffer) {
|
||||
for (let i = 0; i < buffer.length; i++) {
|
||||
let otpData = TOTP.copy(buffer[i]).getOTP()
|
||||
console.log(otpData.otp)
|
||||
let otpData = TOTP.copy(buffer[i]).getOTP();
|
||||
renderData[i] = {
|
||||
OTP: RenderOTPValue(i, otpData.otp),
|
||||
expireBar: RenderExpireBar(i, otpData.createdTime, buffer[i].fetchTime)
|
||||
}
|
||||
expireBar: RenderExpireBar(
|
||||
i,
|
||||
otpData.createdTime,
|
||||
buffer[i].fetchTime
|
||||
),
|
||||
};
|
||||
setInterval(() => {
|
||||
const expireDif = Math.abs((((Date.now() - otpData.createdTime) / 1000)
|
||||
/ buffer[i].fetchTime) - 1)
|
||||
const expireDif = Math.abs(
|
||||
(Date.now() - otpData.createdTime) /
|
||||
1000 /
|
||||
buffer[i].fetchTime -
|
||||
1
|
||||
);
|
||||
|
||||
renderData[i].expireBar.setProperty(prop.MORE, {
|
||||
end_angle: (expireDif * 360) - 90,
|
||||
end_angle: expireDif * 360 - 90,
|
||||
color: expireDif > 0.25 ? 0x1ca9c9 : 0xfa0404,
|
||||
})
|
||||
});
|
||||
|
||||
if (otpData.expireTime < Date.now()) {
|
||||
otpData = TOTP.copy(buffer[i]).getOTP()
|
||||
otpData = TOTP.copy(buffer[i]).getOTP();
|
||||
renderData[i].OTP.setProperty(prop.MORE, {
|
||||
text: otpData.otp
|
||||
})
|
||||
text: otpData.otp,
|
||||
});
|
||||
}
|
||||
}, 50)
|
||||
}, 50);
|
||||
}
|
||||
}
|
@ -1,18 +1,18 @@
|
||||
import { getDeviceInfo } from '@zos/device'
|
||||
import { push } from '@zos/router'
|
||||
import { createWidget, widget, align, text_style } from '@zos/ui'
|
||||
import { getDeviceInfo } from "@zos/device";
|
||||
import { push } from "@zos/router";
|
||||
import { createWidget, widget, align, text_style } from "@zos/ui";
|
||||
|
||||
//Renderer module for TOTPs page
|
||||
|
||||
const { width, height } = getDeviceInfo()
|
||||
const buttonWidth = width - width / 20 //Width of container
|
||||
const buttonHeight = height / 4 //Height of container
|
||||
const containerColor = 0x303030 //Color of container
|
||||
const containerRadius = 20 //Corner radius of container
|
||||
const { width, height } = getDeviceInfo();
|
||||
const buttonWidth = width - width / 20; //Width of container
|
||||
const buttonHeight = height / 4; //Height of container
|
||||
const containerColor = 0x303030; //Color of container
|
||||
const containerRadius = 20; //Corner radius of container
|
||||
|
||||
const textColor = 0xa0a0a0 //Color of TOTP description text
|
||||
const textSize = 24 //Size of TOTP description text
|
||||
const statusBarPading = 65
|
||||
const textColor = 0xa0a0a0; //Color of TOTP description text
|
||||
const textSize = 24; //Size of TOTP description text
|
||||
const statusBarPading = 65;
|
||||
|
||||
/** Function for render box container for TOTP values
|
||||
*
|
||||
@ -21,15 +21,15 @@ const statusBarPading = 65
|
||||
* @param {string} client client of TOTP
|
||||
*/
|
||||
export function RenderTOTPContainer(position, issuer, client) {
|
||||
const yPos = getYPos(position)
|
||||
const yPos = getYPos(position);
|
||||
createWidget(widget.FILL_RECT, {
|
||||
x: width / 2 - buttonWidth / 2,
|
||||
y: yPos,
|
||||
w: buttonWidth,
|
||||
h: buttonHeight,
|
||||
color: containerColor,
|
||||
radius: containerRadius
|
||||
})
|
||||
radius: containerRadius,
|
||||
});
|
||||
createWidget(widget.TEXT, {
|
||||
x: 0 + (width - buttonWidth) / 2,
|
||||
y: yPos + 10,
|
||||
@ -40,8 +40,8 @@ export function RenderTOTPContainer(position, issuer, client) {
|
||||
align_h: align.CENTER_H,
|
||||
align_v: align.CENTER_V,
|
||||
text_style: text_style.NONE,
|
||||
text: issuer + ': ' + client
|
||||
})
|
||||
text: issuer + ": " + client,
|
||||
});
|
||||
}
|
||||
|
||||
/** Render OTP Value on container
|
||||
@ -51,7 +51,7 @@ export function RenderTOTPContainer(position, issuer, client) {
|
||||
* @returns widget with OTP
|
||||
*/
|
||||
export function RenderOTPValue(position, otpValue) {
|
||||
const yPos = getYPos(position)
|
||||
const yPos = getYPos(position);
|
||||
return createWidget(widget.TEXT, {
|
||||
x: 0,
|
||||
y: yPos + 50,
|
||||
@ -62,8 +62,8 @@ export function RenderOTPValue(position, otpValue) {
|
||||
align_h: align.CENTER_H,
|
||||
align_v: align.CENTER_V,
|
||||
text_style: text_style.NONE,
|
||||
text: otpValue
|
||||
})
|
||||
text: otpValue,
|
||||
});
|
||||
}
|
||||
|
||||
/** Render expire bar
|
||||
@ -74,9 +74,10 @@ export function RenderOTPValue(position, otpValue) {
|
||||
* @returns widget with bar
|
||||
*/
|
||||
export function RenderExpireBar(position, createdTime, fetchTime) {
|
||||
const yPos = getYPos(position)
|
||||
const expireDif = Math.abs((((Date.now() - createdTime) / 1000)
|
||||
/ fetchTime) - 1)
|
||||
const yPos = getYPos(position);
|
||||
const expireDif = Math.abs(
|
||||
(Date.now() - createdTime) / 1000 / fetchTime - 1
|
||||
);
|
||||
return createWidget(widget.ARC, {
|
||||
x: buttonWidth - 50,
|
||||
y: yPos + 52,
|
||||
@ -85,8 +86,8 @@ export function RenderExpireBar(position, createdTime, fetchTime) {
|
||||
line_width: 5,
|
||||
color: expireDif > 0.25 ? 0x1ca9c9 : 0xfa0404,
|
||||
start_angle: -90,
|
||||
end_angle: (expireDif * 360) - 90,
|
||||
text: expireDif
|
||||
end_angle: expireDif * 360 - 90,
|
||||
text: expireDif,
|
||||
});
|
||||
}
|
||||
|
||||
@ -100,17 +101,19 @@ export function RenderAddButton(pagePath) {
|
||||
y: height / 2 - 20,
|
||||
w: 80,
|
||||
h: 80,
|
||||
text: '+',
|
||||
text: "+",
|
||||
radius: 50,
|
||||
text_size: 40,
|
||||
normal_color: 0x303030,
|
||||
press_color: 0x181c18,
|
||||
click_func: () => {
|
||||
push({
|
||||
url: pagePath
|
||||
})
|
||||
}
|
||||
})
|
||||
url: pagePath,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function getYPos(position) { return position * (buttonHeight + 10) + statusBarPading }
|
||||
function getYPos(position) {
|
||||
return position * (buttonHeight + 10) + statusBarPading;
|
||||
}
|
||||
|
18
page/tip.js
18
page/tip.js
@ -1,6 +1,6 @@
|
||||
import { createWidget, widget, align } from "@zos/ui";
|
||||
import { getDeviceInfo } from "@zos/device";
|
||||
import { onGesture, GESTURE_LEFT } from '@zos/interaction'
|
||||
import { onGesture, GESTURE_LEFT } from "@zos/interaction";
|
||||
import { back } from "@zos/router";
|
||||
import { BasePage } from "@zeppos/zml/base-page";
|
||||
Page(
|
||||
@ -9,13 +9,13 @@ Page(
|
||||
onGesture({
|
||||
callback(event) {
|
||||
if (event === GESTURE_LEFT) {
|
||||
back()
|
||||
back();
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
},
|
||||
build() {
|
||||
const { width, height } = getDeviceInfo()
|
||||
const { width, height } = getDeviceInfo();
|
||||
createWidget(widget.TEXT, {
|
||||
x: 0,
|
||||
w: width,
|
||||
@ -24,8 +24,8 @@ Page(
|
||||
text_size: 30,
|
||||
align_h: align.CENTER_H,
|
||||
align_v: align.CENTER_V,
|
||||
text: 'To add TOTP record open\n settings on Zepp app'
|
||||
text: "To add TOTP record open\n settings on Zepp app",
|
||||
});
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getTOTPByLink } from './utils/queryParser.js'
|
||||
import { getTOTPByLink } from "./utils/queryParser.js";
|
||||
|
||||
let _props = null;
|
||||
|
||||
@ -6,19 +6,21 @@ AppSettingsPage({
|
||||
build(props) {
|
||||
_props = props;
|
||||
|
||||
const storage = props.settingsStorage.getItem("TOTPs") ?? []
|
||||
const totpEntrys = GetTOTPList(storage)
|
||||
const storage = JSON.parse(
|
||||
props.settingsStorage.getItem("TOTPs") ?? "[]"
|
||||
);
|
||||
const totpEntrys = GetTOTPList(storage);
|
||||
const createButton = TextInput({
|
||||
placeholder: "otpauth://",
|
||||
label: "Add new OTP Link",
|
||||
onChange: (changes) => {
|
||||
var link = getTOTPByLink(changes)
|
||||
var link = getTOTPByLink(changes);
|
||||
if (link == null) {
|
||||
console.log("link is invalid")
|
||||
console.log("link is invalid");
|
||||
return;
|
||||
}
|
||||
storage.push(link)
|
||||
updateStorage(storage)
|
||||
storage.push(link);
|
||||
updateStorage(storage);
|
||||
},
|
||||
labelStyle: {
|
||||
backgroundColor: "#14213D",
|
||||
@ -29,8 +31,8 @@ AppSettingsPage({
|
||||
flexGrow: 1,
|
||||
fontSize: "20px",
|
||||
color: "#FFFFFF",
|
||||
borderRadius: "5px"
|
||||
}
|
||||
borderRadius: "5px",
|
||||
},
|
||||
});
|
||||
|
||||
var body = Section(
|
||||
@ -62,7 +64,7 @@ AppSettingsPage({
|
||||
)
|
||||
),
|
||||
...totpEntrys,
|
||||
createButton
|
||||
createButton,
|
||||
]
|
||||
);
|
||||
return body;
|
||||
@ -79,11 +81,10 @@ function GetTOTPList(storage){
|
||||
label: "Change OTP link",
|
||||
onChange: (changes) => {
|
||||
try {
|
||||
storage[elementId] = getTOTPByLink(changes)
|
||||
updateStorage(storage)
|
||||
}
|
||||
catch(err){
|
||||
console.log(err)
|
||||
storage[elementId] = getTOTPByLink(changes);
|
||||
updateStorage(storage);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
},
|
||||
labelStyle: {
|
||||
@ -96,7 +97,7 @@ function GetTOTPList(storage){
|
||||
flexGrow: 1,
|
||||
fontSize: "20px",
|
||||
color: "#E5E5E5",
|
||||
borderRadius: "5px"
|
||||
borderRadius: "5px",
|
||||
},
|
||||
});
|
||||
const textBig = Text(
|
||||
@ -104,35 +105,35 @@ function GetTOTPList(storage){
|
||||
align: "center",
|
||||
style: {
|
||||
color: "#ffffff",
|
||||
fontSize: "16px"
|
||||
fontSize: "16px",
|
||||
},
|
||||
paragraph: true,
|
||||
},
|
||||
`${element.issuer}: ${element.client}`
|
||||
);
|
||||
const delButton = Button(
|
||||
{
|
||||
const delButton = Button({
|
||||
onClick: () => {
|
||||
storage = storage.filter(x => storage.indexOf(x) != elementId)
|
||||
updateStorage(storage)
|
||||
storage = storage.filter(
|
||||
(x) => storage.indexOf(x) != elementId
|
||||
);
|
||||
updateStorage(storage);
|
||||
},
|
||||
style: {
|
||||
backgroundColor: "#ba181b",
|
||||
fontSize: "18px",
|
||||
color: "#ffffff",
|
||||
height: "fit-content",
|
||||
margin: "10px"
|
||||
margin: "10px",
|
||||
},
|
||||
label: "DEL"
|
||||
}
|
||||
);
|
||||
label: "DEL",
|
||||
});
|
||||
const text = Text(
|
||||
{
|
||||
style: {
|
||||
color: "#ffffff",
|
||||
fontSize: "14px"
|
||||
fontSize: "14px",
|
||||
},
|
||||
align: "center"
|
||||
align: "center",
|
||||
},
|
||||
`${element.hashType} | ${element.digits} digits | ${element.fetchTime} seconds | offset ${element.timeOffset} seconds`
|
||||
);
|
||||
@ -142,21 +143,30 @@ function GetTOTPList(storage){
|
||||
textAlign: "center",
|
||||
border: "2px solid white",
|
||||
borderRadius: "5px",
|
||||
margin: "10px"
|
||||
margin: "10px",
|
||||
},
|
||||
},
|
||||
[textBig, text, View({style: {
|
||||
[
|
||||
textBig,
|
||||
text,
|
||||
View(
|
||||
{
|
||||
style: {
|
||||
display: "grid",
|
||||
gridTemplateColumns: "1fr 100px"
|
||||
}}, [textInput, delButton])]
|
||||
gridTemplateColumns: "1fr 100px",
|
||||
},
|
||||
},
|
||||
[textInput, delButton]
|
||||
),
|
||||
]
|
||||
);
|
||||
totpEntrys.push({ text: text, view: view });
|
||||
counter++;
|
||||
});
|
||||
|
||||
return totpEntrys.map(x => x.view);
|
||||
return totpEntrys.map((x) => x.view);
|
||||
}
|
||||
|
||||
function updateStorage(storage) {
|
||||
_props.settingsStorage.setItem('TOTPs', storage)
|
||||
_props.settingsStorage.setItem("TOTPs", JSON.stringify(storage));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user