Browse Source

Work in progress

kb/add-usage-guide
Matthew Aaron Raymer 2 years ago
parent
commit
6325bcbe35
  1. 50
      package-lock.json
  2. 2
      package.json
  3. 2
      src/constants/app.ts
  4. 27
      src/libs/crypto/index.ts
  5. 4
      src/main.ts
  6. 2
      src/views/AccountViewView.vue
  7. 40
      src/views/NewEditProjectView.vue

50
package-lock.json

@ -22,6 +22,7 @@
"@veramo/key-manager": "^4.1.1", "@veramo/key-manager": "^4.1.1",
"@vueuse/core": "^9.6.0", "@vueuse/core": "^9.6.0",
"@zxing/text-encoding": "^0.9.0", "@zxing/text-encoding": "^0.9.0",
"axios": "^1.2.2",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"core-js": "^3.26.1", "core-js": "^3.26.1",
"dexie": "^3.2.2", "dexie": "^3.2.2",
@ -40,6 +41,7 @@
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"register-service-worker": "^1.7.2", "register-service-worker": "^1.7.2",
"vue": "^3.2.45", "vue": "^3.2.45",
"vue-axios": "^3.5.2",
"vue-class-component": "^8.0.0-0", "vue-class-component": "^8.0.0-0",
"vue-property-decorator": "^9.1.2", "vue-property-decorator": "^9.1.2",
"vue-router": "^4.1.6", "vue-router": "^4.1.6",
@ -9685,9 +9687,7 @@
"node_modules/asynckit": { "node_modules/asynckit": {
"version": "0.4.0", "version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
"optional": true,
"peer": true
}, },
"node_modules/at-least-node": { "node_modules/at-least-node": {
"version": "1.0.0", "version": "1.0.0",
@ -9744,6 +9744,29 @@
"postcss": "^8.1.0" "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": { "node_modules/b64-lite": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/b64-lite/-/b64-lite-1.4.0.tgz", "resolved": "https://registry.npmjs.org/b64-lite/-/b64-lite-1.4.0.tgz",
@ -11025,8 +11048,6 @@
"version": "1.0.8", "version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"optional": true,
"peer": true,
"dependencies": { "dependencies": {
"delayed-stream": "~1.0.0" "delayed-stream": "~1.0.0"
}, },
@ -12103,8 +12124,6 @@
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"optional": true,
"peer": true,
"engines": { "engines": {
"node": ">=0.4.0" "node": ">=0.4.0"
} }
@ -14582,7 +14601,6 @@
"version": "1.15.2", "version": "1.15.2",
"resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.2.tgz", "resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.2.tgz",
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
"dev": true,
"funding": [ "funding": [
{ {
"type": "individual", "type": "individual",
@ -19049,7 +19067,6 @@
"version": "1.52.0", "version": "1.52.0",
"resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz", "resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"devOptional": true,
"engines": { "engines": {
"node": ">= 0.6" "node": ">= 0.6"
} }
@ -19058,7 +19075,6 @@
"version": "2.1.35", "version": "2.1.35",
"resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz", "resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"devOptional": true,
"dependencies": { "dependencies": {
"mime-db": "1.52.0" "mime-db": "1.52.0"
}, },
@ -21430,6 +21446,11 @@
"node": ">= 0.10" "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": { "node_modules/pseudomap": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmmirror.com/pseudomap/-/pseudomap-1.0.2.tgz", "resolved": "https://registry.npmmirror.com/pseudomap/-/pseudomap-1.0.2.tgz",
@ -25254,6 +25275,15 @@
"@vue/shared": "3.2.45" "@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": { "node_modules/vue-class-component": {
"version": "8.0.0-rc.1", "version": "8.0.0-rc.1",
"resolved": "https://registry.npmmirror.com/vue-class-component/-/vue-class-component-8.0.0-rc.1.tgz", "resolved": "https://registry.npmmirror.com/vue-class-component/-/vue-class-component-8.0.0-rc.1.tgz",

2
package.json

@ -22,6 +22,7 @@
"@veramo/key-manager": "^4.1.1", "@veramo/key-manager": "^4.1.1",
"@vueuse/core": "^9.6.0", "@vueuse/core": "^9.6.0",
"@zxing/text-encoding": "^0.9.0", "@zxing/text-encoding": "^0.9.0",
"axios": "^1.2.2",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"core-js": "^3.26.1", "core-js": "^3.26.1",
"dexie": "^3.2.2", "dexie": "^3.2.2",
@ -40,6 +41,7 @@
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"register-service-worker": "^1.7.2", "register-service-worker": "^1.7.2",
"vue": "^3.2.45", "vue": "^3.2.45",
"vue-axios": "^3.5.2",
"vue-class-component": "^8.0.0-0", "vue-class-component": "^8.0.0-0",
"vue-property-decorator": "^9.1.2", "vue-property-decorator": "^9.1.2",
"vue-router": "^4.1.6", "vue-router": "^4.1.6",

2
src/constants/app.ts

@ -4,4 +4,6 @@
export enum AppString { export enum AppString {
APP_NAME = "Kickstart for time", APP_NAME = "Kickstart for time",
VERSION = "0.1", VERSION = "0.1",
DEFAULT_ENDORSER_API_SERVER = 'https://endorser.ch:3000',
DEFAULT_ENDORSER_VIEW_SERVER = 'https://endorser.ch'
} }

27
src/libs/crypto/index.ts

@ -4,8 +4,8 @@ import { getRandomBytesSync } from "ethereum-cryptography/random";
import { entropyToMnemonic } from "ethereum-cryptography/bip39"; import { entropyToMnemonic } from "ethereum-cryptography/bip39";
import { wordlist } from "ethereum-cryptography/bip39/wordlists/english"; import { wordlist } from "ethereum-cryptography/bip39/wordlists/english";
import { HDNode } from "@ethersproject/hdnode"; import { HDNode } from "@ethersproject/hdnode";
import * as didJwt from 'did-jwt'; import * as didJwt from "did-jwt";
import * as u8a from 'uint8arrays' import * as u8a from "uint8arrays";
/** /**
* *
@ -39,14 +39,13 @@ export const newIdentifier = (
}; };
}; };
/** /**
* *
* *
* @param {string} mnemonic * @param {string} mnemonic
* @return {*} {[string, string, string, string]} * @return {*} {[string, string, string, string]}
*/ */
const deriveAddress = ( export const deriveAddress = (
mnemonic: string mnemonic: string
): [string, string, string, string] => { ): [string, string, string, string] => {
const UPORT_ROOT_DERIVATION_PATH = "m/7696500'/0'/0'/0'"; const UPORT_ROOT_DERIVATION_PATH = "m/7696500'/0'/0'/0'";
@ -61,7 +60,6 @@ const deriveAddress = (
return [address, privateHex, publicHex, UPORT_ROOT_DERIVATION_PATH]; return [address, privateHex, publicHex, UPORT_ROOT_DERIVATION_PATH];
}; };
/** /**
* *
* *
@ -74,18 +72,19 @@ export const createIdentifier = (): string => {
return mnemonic; return mnemonic;
}; };
/** /**
* Retreive an access token * Retreive an access token
* *
* @param {IIdentifier} identifier * @param {IIdentifier} identifier
* @return {*} * @return {*}
*/ */
const accessToken = async (identifier: IIdentifier) => { export const accessToken = async (identifier: IIdentifier) => {
const did: string = identifier.did; const did: string = identifier.did;
const privateKeyHex: string = identifier.keys[0].privateKeyHex as string; const privateKeyHex: string = identifier.keys[0].privateKeyHex as string;
const input = privateKeyHex.startsWith('0x') ? privateKeyHex.substring(2) : privateKeyHex; const input = privateKeyHex.startsWith("0x")
const privateKeyBytes = u8a.fromString(input.toLowerCase(), 'base16') ? privateKeyHex.substring(2)
: privateKeyHex;
const privateKeyBytes = u8a.fromString(input.toLowerCase(), "base16");
const signer = didJwt.ES256KSigner(privateKeyBytes, true); const signer = didJwt.ES256KSigner(privateKeyBytes, true);
@ -94,6 +93,10 @@ const accessToken = async (identifier: IIdentifier) => {
const uportTokenPayload = { exp: endEpoch, iat: nowEpoch, iss: did }; const uportTokenPayload = { exp: endEpoch, iat: nowEpoch, iss: did };
const alg = undefined; // defaults to 'ES256K', more standardized but harder to verify vs ES256K-R 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; return jwt;
}; };

4
src/main.ts

@ -3,6 +3,9 @@ import { createApp } from "vue";
import App from "./App.vue"; import App from "./App.vue";
import "./registerServiceWorker"; import "./registerServiceWorker";
import router from "./router"; import router from "./router";
import axios from "axios";
import VueAxios from "vue-axios";
import "./assets/styles/tailwind.css"; import "./assets/styles/tailwind.css";
import { library } from "@fortawesome/fontawesome-svg-core"; import { library } from "@fortawesome/fontawesome-svg-core";
@ -49,5 +52,6 @@ import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
createApp(App) createApp(App)
.component("fa", FontAwesomeIcon) .component("fa", FontAwesomeIcon)
.use(createPinia()) .use(createPinia())
.use(VueAxios, axios)
.use(router) .use(router)
.mount("#app"); .mount("#app");

2
src/views/AccountViewView.vue

@ -213,7 +213,6 @@ export default class AccountViewView extends Vue {
await db.open(); await db.open();
const num_accounts = await db.accounts.count(); const num_accounts = await db.accounts.count();
if (num_accounts === 0) { if (num_accounts === 0) {
console.log("...");
await db.accounts.add({ await db.accounts.add({
publicKey: newId.keys[0].publicKeyHex, publicKey: newId.keys[0].publicKeyHex,
mnemonic: this.mnemonic, mnemonic: this.mnemonic,
@ -223,7 +222,6 @@ export default class AccountViewView extends Vue {
} }
useAppStore().setCondition("registered"); useAppStore().setCondition("registered");
} catch (err) { } catch (err) {
console.log("Error!");
console.log(err); console.log(err);
} }
} }

40
src/views/NewEditProjectView.vue

@ -72,6 +72,9 @@
<script lang="ts"> <script lang="ts">
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import { AppString } from "@/constants/app";
import { db } from "../db";
import { accessToken } from "@/libs/crypto";
@Options({ @Options({
components: {}, components: {},
@ -79,9 +82,44 @@ import { Options, Vue } from "vue-class-component";
export default class NewEditProjectView extends Vue { export default class NewEditProjectView extends Vue {
projectName = ""; projectName = "";
description = ""; description = "";
public async onSaveProjectClick() { public async onSaveProjectClick() {
console.log("Placeholder"); await db.open();
const num_accounts = await db.accounts.count();
if (num_accounts === 0) {
console.log("Problem! Should have a profile!");
} else {
const accounts = await db.accounts.toArray();
const identity = JSON.parse(accounts[0].identity);
const address = identity.did;
const vcClaim = {
"@context": "https://schema.org",
"@type": "Plan",
identifier: address,
name: this.projectName,
description: this.description,
};
const jwt = "";
const payload = JSON.stringify({ jwtEncoded: jwt});
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
const url = endorserApiServer + "/api/claim";
const token = await accessToken(identity)
const headers = {
'Content-Type': 'application/json',
'Uport-Push-Token': token
}
try {
let resp = await this.axios.post(url, payload, { headers });
} catch (error) {
console.log(error);
}
}
} }
public onCancelClick() { public onCancelClick() {
this.$router.back(); this.$router.back();
} }

Loading…
Cancel
Save