From 6325bcbe357f9e9286e03bba8ee4ca0a3aa6ce98 Mon Sep 17 00:00:00 2001 From: Matthew Aaron Raymer Date: Tue, 3 Jan 2023 17:28:23 +0800 Subject: [PATCH] Work in progress --- package-lock.json | 50 +++++++++++++++++++++++++------- package.json | 2 ++ src/constants/app.ts | 2 ++ src/libs/crypto/index.ts | 27 +++++++++-------- src/main.ts | 4 +++ src/views/AccountViewView.vue | 2 -- src/views/NewEditProjectView.vue | 40 ++++++++++++++++++++++++- 7 files changed, 102 insertions(+), 25 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0fb200fe8..cbbedcc87 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "@veramo/key-manager": "^4.1.1", "@vueuse/core": "^9.6.0", "@zxing/text-encoding": "^0.9.0", + "axios": "^1.2.2", "class-transformer": "^0.5.1", "core-js": "^3.26.1", "dexie": "^3.2.2", @@ -40,6 +41,7 @@ "reflect-metadata": "^0.1.13", "register-service-worker": "^1.7.2", "vue": "^3.2.45", + "vue-axios": "^3.5.2", "vue-class-component": "^8.0.0-0", "vue-property-decorator": "^9.1.2", "vue-router": "^4.1.6", @@ -9685,9 +9687,7 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "optional": true, - "peer": true + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/at-least-node": { "version": "1.0.0", @@ -9744,6 +9744,29 @@ "postcss": "^8.1.0" } }, + "node_modules/axios": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.2.2.tgz", + "integrity": "sha512-bz/J4gS2S3I7mpN/YZfGFTqhXTYzRho8Ay38w2otuuDR322KzFIWm/4W2K6gIwvWaws5n+mnb7D1lN9uD+QH6Q==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/b64-lite": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/b64-lite/-/b64-lite-1.4.0.tgz", @@ -11025,8 +11048,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "optional": true, - "peer": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -12103,8 +12124,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "optional": true, - "peer": true, "engines": { "node": ">=0.4.0" } @@ -14582,7 +14601,6 @@ "version": "1.15.2", "resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.2.tgz", "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", - "dev": true, "funding": [ { "type": "individual", @@ -19049,7 +19067,6 @@ "version": "1.52.0", "resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "devOptional": true, "engines": { "node": ">= 0.6" } @@ -19058,7 +19075,6 @@ "version": "2.1.35", "resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "devOptional": true, "dependencies": { "mime-db": "1.52.0" }, @@ -21430,6 +21446,11 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/pseudomap": { "version": "1.0.2", "resolved": "https://registry.npmmirror.com/pseudomap/-/pseudomap-1.0.2.tgz", @@ -25254,6 +25275,15 @@ "@vue/shared": "3.2.45" } }, + "node_modules/vue-axios": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/vue-axios/-/vue-axios-3.5.2.tgz", + "integrity": "sha512-GP+dct7UlAWkl1qoP3ppw0z6jcSua5/IrMpjB5O8bh089iIiJ+hdxPYH2NPEpajlYgkW5EVMP95ttXWdas1O0g==", + "peerDependencies": { + "axios": "*", + "vue": "^3.0.0 || ^2.0.0" + } + }, "node_modules/vue-class-component": { "version": "8.0.0-rc.1", "resolved": "https://registry.npmmirror.com/vue-class-component/-/vue-class-component-8.0.0-rc.1.tgz", diff --git a/package.json b/package.json index 0df90932f..178ca01e7 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@veramo/key-manager": "^4.1.1", "@vueuse/core": "^9.6.0", "@zxing/text-encoding": "^0.9.0", + "axios": "^1.2.2", "class-transformer": "^0.5.1", "core-js": "^3.26.1", "dexie": "^3.2.2", @@ -40,6 +41,7 @@ "reflect-metadata": "^0.1.13", "register-service-worker": "^1.7.2", "vue": "^3.2.45", + "vue-axios": "^3.5.2", "vue-class-component": "^8.0.0-0", "vue-property-decorator": "^9.1.2", "vue-router": "^4.1.6", diff --git a/src/constants/app.ts b/src/constants/app.ts index 917b063bf..d684cd71e 100644 --- a/src/constants/app.ts +++ b/src/constants/app.ts @@ -4,4 +4,6 @@ export enum AppString { APP_NAME = "Kickstart for time", VERSION = "0.1", + DEFAULT_ENDORSER_API_SERVER = 'https://endorser.ch:3000', + DEFAULT_ENDORSER_VIEW_SERVER = 'https://endorser.ch' } diff --git a/src/libs/crypto/index.ts b/src/libs/crypto/index.ts index d386ef461..9234baace 100644 --- a/src/libs/crypto/index.ts +++ b/src/libs/crypto/index.ts @@ -4,8 +4,8 @@ import { getRandomBytesSync } from "ethereum-cryptography/random"; import { entropyToMnemonic } from "ethereum-cryptography/bip39"; import { wordlist } from "ethereum-cryptography/bip39/wordlists/english"; import { HDNode } from "@ethersproject/hdnode"; -import * as didJwt from 'did-jwt'; -import * as u8a from 'uint8arrays' +import * as didJwt from "did-jwt"; +import * as u8a from "uint8arrays"; /** * @@ -39,14 +39,13 @@ export const newIdentifier = ( }; }; - /** * * * @param {string} mnemonic * @return {*} {[string, string, string, string]} */ -const deriveAddress = ( +export const deriveAddress = ( mnemonic: string ): [string, string, string, string] => { const UPORT_ROOT_DERIVATION_PATH = "m/7696500'/0'/0'/0'"; @@ -61,7 +60,6 @@ const deriveAddress = ( return [address, privateHex, publicHex, UPORT_ROOT_DERIVATION_PATH]; }; - /** * * @@ -74,18 +72,19 @@ export const createIdentifier = (): string => { return mnemonic; }; - /** * Retreive an access token * * @param {IIdentifier} identifier - * @return {*} + * @return {*} */ -const accessToken = async (identifier: IIdentifier) => { +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.ES256KSigner(privateKeyBytes, true); @@ -94,6 +93,10 @@ const accessToken = async (identifier: IIdentifier) => { const uportTokenPayload = { exp: endEpoch, iat: nowEpoch, iss: did }; const alg = undefined; // defaults to 'ES256K', more standardized but harder to verify vs ES256K-R - const jwt: string = await didJwt.createJWT(uportTokenPayload, { alg, issuer: did, signer }); + const jwt: string = await didJwt.createJWT(uportTokenPayload, { + alg, + issuer: did, + signer, + }); return jwt; -}; \ No newline at end of file +}; diff --git a/src/main.ts b/src/main.ts index 01814f63f..a8fa5f4ea 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,6 +3,9 @@ import { createApp } from "vue"; import App from "./App.vue"; import "./registerServiceWorker"; import router from "./router"; +import axios from "axios"; +import VueAxios from "vue-axios"; + import "./assets/styles/tailwind.css"; import { library } from "@fortawesome/fontawesome-svg-core"; @@ -49,5 +52,6 @@ import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; createApp(App) .component("fa", FontAwesomeIcon) .use(createPinia()) + .use(VueAxios, axios) .use(router) .mount("#app"); diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index d634a3549..ea60473ae 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -213,7 +213,6 @@ export default class AccountViewView extends Vue { await db.open(); const num_accounts = await db.accounts.count(); if (num_accounts === 0) { - console.log("..."); await db.accounts.add({ publicKey: newId.keys[0].publicKeyHex, mnemonic: this.mnemonic, @@ -223,7 +222,6 @@ export default class AccountViewView extends Vue { } useAppStore().setCondition("registered"); } catch (err) { - console.log("Error!"); console.log(err); } } diff --git a/src/views/NewEditProjectView.vue b/src/views/NewEditProjectView.vue index 69160a5ef..7da398922 100644 --- a/src/views/NewEditProjectView.vue +++ b/src/views/NewEditProjectView.vue @@ -72,6 +72,9 @@