From f021fcdb1c88f4569bd6297ec626ee5c3421a01b Mon Sep 17 00:00:00 2001 From: Matthew Aaron Raymer Date: Wed, 4 Jan 2023 17:05:08 +0800 Subject: [PATCH] New Project --- src/constants/app.ts | 4 ++-- src/libs/crypto/index.ts | 11 +++++++++++ src/views/NewEditProjectView.vue | 26 +++++++++++++++++++------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/constants/app.ts b/src/constants/app.ts index d684cd71..857e2256 100644 --- a/src/constants/app.ts +++ b/src/constants/app.ts @@ -4,6 +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' + DEFAULT_ENDORSER_API_SERVER = 'https://test.endorser.ch:8000', + DEFAULT_ENDORSER_VIEW_SERVER = 'https://test.endorser.ch' } diff --git a/src/libs/crypto/index.ts b/src/libs/crypto/index.ts index 9234baac..f53c88b6 100644 --- a/src/libs/crypto/index.ts +++ b/src/libs/crypto/index.ts @@ -100,3 +100,14 @@ export const accessToken = async (identifier: IIdentifier) => { }); return jwt; }; + +export const sign = async (privateKeyHex: string) => { + const input = privateKeyHex.startsWith("0x") + ? privateKeyHex.substring(2) + : privateKeyHex; + const privateKeyBytes = u8a.fromString(input.toLowerCase(), "base16"); + + const signer = didJwt.ES256KSigner(privateKeyBytes, true); + + return signer; +}; \ No newline at end of file diff --git a/src/views/NewEditProjectView.vue b/src/views/NewEditProjectView.vue index 7da39892..86358389 100644 --- a/src/views/NewEditProjectView.vue +++ b/src/views/NewEditProjectView.vue @@ -74,7 +74,8 @@ import { Options, Vue } from "vue-class-component"; import { AppString } from "@/constants/app"; import { db } from "../db"; -import { accessToken } from "@/libs/crypto"; +import { accessToken, sign } from "@/libs/crypto"; +import * as didJwt from 'did-jwt' @Options({ components: {}, @@ -95,20 +96,31 @@ export default class NewEditProjectView extends Vue { const address = identity.did; const vcClaim = { "@context": "https://schema.org", - "@type": "Plan", + "@type": "PlanAction", identifier: address, name: this.projectName, description: this.description, }; - const jwt = ""; - const payload = JSON.stringify({ jwtEncoded: jwt}); + const vcPayload = { + sub: "PlanAction", + vc: { + '@context': ['https://www.w3.org/2018/credentials/v1'], + type: ['VerifiableCredential'], + credentialSubject: vcClaim, + } + }; + const signer = await sign(identity.keys[0].privateKeyHex); + const alg = undefined; + const vcJwt: string = await didJwt.createJWT(vcClaim,{ alg, issuer: identity, signer }); + + const payload = JSON.stringify({ jwtEncoded: vcJwt}); const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; const url = endorserApiServer + "/api/claim"; - const token = await accessToken(identity) + const token = await accessToken(identity); const headers = { 'Content-Type': 'application/json', - 'Uport-Push-Token': token - } + 'Authorization': "Bearer " + token + }; try { let resp = await this.axios.post(url, payload, { headers });