From 9d566fa977fe4dece3aabbc98fbf38d726a54331 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Fri, 6 Jan 2023 19:25:53 -0700 Subject: [PATCH 1/7] fix: use SimpleSigner directly from did-jwt --- src/libs/crypto/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/crypto/index.ts b/src/libs/crypto/index.ts index 8d8df5a..a71cec1 100644 --- a/src/libs/crypto/index.ts +++ b/src/libs/crypto/index.ts @@ -122,7 +122,7 @@ export const accessToken = async (identifier: IIdentifier) => { : privateKeyHex; const privateKeyBytes = u8a.fromString(input.toLowerCase(), "base16"); - const signer = didJwt.ES256KSigner(privateKeyBytes, true); + const signer = didJwt.SimpleSigner(privateKeyHex); const nowEpoch = Math.floor(Date.now() / 1000); const endEpoch = nowEpoch + 60; // add one minute @@ -143,7 +143,7 @@ export const sign = async (privateKeyHex: string) => { : privateKeyHex; const privateKeyBytes = u8a.fromString(input.toLowerCase(), "base16"); - const signer = didJwt.ES256KSigner(privateKeyBytes, true); + const signer = didJwt.SimpleSigner(privateKeyHex); return signer; }; From ba856630487df8a985f60488e0116e7bcf428e29 Mon Sep 17 00:00:00 2001 From: Matthew Aaron Raymer Date: Sat, 7 Jan 2023 13:19:04 +0800 Subject: [PATCH 2/7] Linted --- src/libs/crypto/index.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libs/crypto/index.ts b/src/libs/crypto/index.ts index a71cec1..eb4e6b8 100644 --- a/src/libs/crypto/index.ts +++ b/src/libs/crypto/index.ts @@ -117,10 +117,10 @@ export const createIdentifier = (): string => { export const accessToken = async (identifier: IIdentifier) => { const did: string = identifier.did; const privateKeyHex: string = identifier.keys[0].privateKeyHex as string; - const input = privateKeyHex.startsWith("0x") - ? privateKeyHex.substring(2) - : privateKeyHex; - const privateKeyBytes = u8a.fromString(input.toLowerCase(), "base16"); + //const input = privateKeyHex.startsWith("0x") + // ? privateKeyHex.substring(2) + // : privateKeyHex; + //const privateKeyBytes = u8a.fromString(input.toLowerCase(), "base16"); const signer = didJwt.SimpleSigner(privateKeyHex); @@ -138,10 +138,10 @@ export const accessToken = async (identifier: IIdentifier) => { }; export const sign = async (privateKeyHex: string) => { - const input = privateKeyHex.startsWith("0x") - ? privateKeyHex.substring(2) - : privateKeyHex; - const privateKeyBytes = u8a.fromString(input.toLowerCase(), "base16"); + //const input = privateKeyHex.startsWith("0x") + // ? privateKeyHex.substring(2) + // : privateKeyHex; + // const privateKeyBytes = u8a.fromString(input.toLowerCase(), "base16"); const signer = didJwt.SimpleSigner(privateKeyHex); From 487997b87cbdaffac74f6ca899a9319c34b98e8f Mon Sep 17 00:00:00 2001 From: Matthew Aaron Raymer Date: Mon, 9 Jan 2023 15:10:05 +0800 Subject: [PATCH 3/7] Adding a less complex router --- src/router/index.ts | 47 ++++++++++---------------------- src/views/NewEditProjectView.vue | 9 ++++-- src/views/ProjectViewView.vue | 7 ++++- 3 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 9697d48..38611c9 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -7,13 +7,19 @@ const routes: Array = [ name: "home", component: () => import(/* webpackChunkName: "start" */ "../views/DiscoverView.vue"), + beforeEnter: (to, from, next) => { + const appStore = useAppStore(); + const isAuthenticated = appStore.condition === "registered"; + if (isAuthenticated) { + next(); + } else { + next({ name: "start" }); + } + }, }, { path: "/about", name: "about", - // route level code-splitting - // this generates a separate chunk (about.[hash].js) for this route - // which is lazy-loaded when the route is visited. component: () => import(/* webpackChunkName: "about" */ "../views/AboutView.vue"), }, @@ -75,6 +81,12 @@ const routes: Array = [ /* webpackChunkName: "new-edit-commitment" */ "../views/NewEditCommitmentView.vue" ), }, + { + path: "/project", + name: "project", + component: () => + import(/* webpackChunkName: "project" */ "../views/ProjectViewView.vue"), + }, { path: "/new-edit-project", name: "new-edit-project", @@ -83,12 +95,6 @@ const routes: Array = [ /* webpackChunkName: "new-edit-project" */ "../views/NewEditProjectView.vue" ), }, - { - path: "/project", - name: "project", - component: () => - import(/* webpackChunkName: "project" */ "../views/ProjectViewView.vue"), - }, { path: "/projects", name: "projects", @@ -111,27 +117,4 @@ const router = createRouter({ routes, }); -router.beforeEach(async (to, from, next) => { - const publicPages = ["/start", "/account", "/import-account"]; - const isPublic = publicPages.includes(to.path); - const appStore = useAppStore(); - console.log(to); - if (to.path === "/" && appStore.condition === "registered") { - next({ path: "/account" }); - } else if (isPublic) { - switch (appStore.condition) { - case "registered": - next(); - break; - default: - next(); - break; - } - } else if (appStore.condition === "uninitialized") { - next({ path: "/start" }); - } else { - next(); - } -}); - export default router; diff --git a/src/views/NewEditProjectView.vue b/src/views/NewEditProjectView.vue index bff74d3..545e3e1 100644 --- a/src/views/NewEditProjectView.vue +++ b/src/views/NewEditProjectView.vue @@ -10,7 +10,6 @@ class="text-lg text-center px-2 py-1 absolute -left-2 -top-1" > - [New/Edit] Project @@ -39,7 +38,7 @@ type="text" placeholder="Project Name" class="block w-full rounded border border-slate-400 mb-4 px-3 py-2" - v-modal="projectName" + v-model="projectName" />