Update with our own SimpleSigner

This commit is contained in:
Matthew Aaron Raymer
2023-01-06 17:30:41 +08:00
parent 39c931cde9
commit 150b35c4c7
2 changed files with 100 additions and 32 deletions

View File

@@ -74,8 +74,9 @@
import { Options, Vue } from "vue-class-component";
import { AppString } from "@/constants/app";
import { db } from "../db";
import { accessToken, sign } from "@/libs/crypto";
import { accessToken, SimpleSigner } from "@/libs/crypto";
import * as didJwt from "did-jwt";
import { IIdentifier } from "@veramo/core";
@Options({
components: {},
@@ -84,40 +85,39 @@ export default class NewEditProjectView extends Vue {
projectName = "";
description = "";
public async onSaveProjectClick() {
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;
// Make a claim
const vcClaim = {
"@context": "https://schema.org",
"@type": "PlanAction",
identifier: address,
name: this.projectName,
description: this.description,
};
// Make a payload for the claim
const vcPayload = {
sub: "PlanAction",
vc: {
"@context": ["https://www.w3.org/2018/credentials/v1"],
type: ["VerifiableCredential"],
credentialSubject: vcClaim,
},
};
// create a signature using private key of identity
const signer = await sign(identity.keys[0].privateKeyHex);
private async SaveProject(identity: IIdentifier) {
const address = identity.did;
// Make a claim
const vcClaim = {
"@context": "https://schema.org",
"@type": "PlanAction",
identifier: address,
name: this.projectName,
description: this.description,
};
// Make a payload for the claim
const vcPayload = {
sub: "PlanAction",
vc: {
"@context": ["https://www.w3.org/2018/credentials/v1"],
type: ["VerifiableCredential"],
credentialSubject: vcClaim,
},
};
// create a signature using private key of identity
if (
identity.keys[0].privateKeyHex !== "undefined" &&
identity.keys[0].privateKeyHex !== null
) {
// eslint-disable-next-line
const privateKeyHex: string = identity.keys[0].privateKeyHex!;
const signer = await SimpleSigner(privateKeyHex);
const alg = undefined;
// create a JWT for the request
const vcJwt: string = await didJwt.createJWT(vcPayload, {
alg,
issuer: identity,
signer,
alg: alg,
issuer: identity.did,
signer: signer,
});
// Make the xhr request payload
@@ -140,6 +140,18 @@ export default class NewEditProjectView extends Vue {
}
}
public async onSaveProjectClick() {
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);
this.SaveProject(identity);
}
}
public onCancelClick() {
this.$router.back();
}