forked from trent_larson/crowd-funder-for-time-pwa
Work in progress
This commit is contained in:
@@ -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'
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,9 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { AppString } from "@/constants/app";
|
||||
import { db } from "../db";
|
||||
import { accessToken } from "@/libs/crypto";
|
||||
|
||||
@Options({
|
||||
components: {},
|
||||
@@ -79,9 +82,44 @@ import { Options, Vue } from "vue-class-component";
|
||||
export default class NewEditProjectView extends Vue {
|
||||
projectName = "";
|
||||
description = "";
|
||||
|
||||
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() {
|
||||
this.$router.back();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user