|
@ -75,7 +75,7 @@ import { Options, Vue } from "vue-class-component"; |
|
|
import { AppString } from "@/constants/app"; |
|
|
import { AppString } from "@/constants/app"; |
|
|
import { db } from "../db"; |
|
|
import { db } from "../db"; |
|
|
import { accessToken, sign } from "@/libs/crypto"; |
|
|
import { accessToken, sign } from "@/libs/crypto"; |
|
|
import * as didJwt from 'did-jwt' |
|
|
import * as didJwt from "did-jwt"; |
|
|
|
|
|
|
|
|
@Options({ |
|
|
@Options({ |
|
|
components: {}, |
|
|
components: {}, |
|
@ -83,13 +83,12 @@ import * as didJwt from 'did-jwt' |
|
|
export default class NewEditProjectView extends Vue { |
|
|
export default class NewEditProjectView extends Vue { |
|
|
projectName = ""; |
|
|
projectName = ""; |
|
|
description = ""; |
|
|
description = ""; |
|
|
|
|
|
|
|
|
public async onSaveProjectClick() { |
|
|
public async onSaveProjectClick() { |
|
|
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("Problem! Should have a profile!"); |
|
|
console.log("Problem! Should have a profile!"); |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
const accounts = await db.accounts.toArray(); |
|
|
const accounts = await db.accounts.toArray(); |
|
|
const identity = JSON.parse(accounts[0].identity); |
|
|
const identity = JSON.parse(accounts[0].identity); |
|
@ -104,30 +103,33 @@ export default class NewEditProjectView extends Vue { |
|
|
const vcPayload = { |
|
|
const vcPayload = { |
|
|
sub: "PlanAction", |
|
|
sub: "PlanAction", |
|
|
vc: { |
|
|
vc: { |
|
|
'@context': ['https://www.w3.org/2018/credentials/v1'], |
|
|
"@context": ["https://www.w3.org/2018/credentials/v1"], |
|
|
type: ['VerifiableCredential'], |
|
|
type: ["VerifiableCredential"], |
|
|
credentialSubject: vcClaim, |
|
|
credentialSubject: vcClaim, |
|
|
} |
|
|
}, |
|
|
}; |
|
|
}; |
|
|
const signer = await sign(identity.keys[0].privateKeyHex); |
|
|
const signer = await sign(identity.keys[0].privateKeyHex); |
|
|
const alg = undefined; |
|
|
const alg = undefined; |
|
|
const vcJwt: string = await didJwt.createJWT(vcClaim,{ alg, issuer: identity, signer }); |
|
|
const vcJwt: string = await didJwt.createJWT(vcPayload, { |
|
|
|
|
|
alg, |
|
|
|
|
|
issuer: identity, |
|
|
|
|
|
signer, |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
const payload = JSON.stringify({ jwtEncoded: vcJwt}); |
|
|
const payload = JSON.stringify({ jwtEncoded: vcJwt }); |
|
|
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; |
|
|
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; |
|
|
const url = endorserApiServer + "/api/claim"; |
|
|
const url = endorserApiServer + "/api/claim"; |
|
|
const token = await accessToken(identity); |
|
|
const token = await accessToken(identity); |
|
|
const headers = { |
|
|
const headers = { |
|
|
'Content-Type': 'application/json', |
|
|
"Content-Type": "application/json", |
|
|
'Authorization': "Bearer " + token |
|
|
Authorization: "Bearer " + token, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
let resp = await this.axios.post(url, payload, { headers }); |
|
|
const resp = await this.axios.post(url, payload, { headers }); |
|
|
|
|
|
console.log(resp.status, resp.data); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.log(error); |
|
|
console.log(error); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|