Skip to content

Commit

Permalink
feat(CAHN Demo): ♻️ util function, fix ordering of parameters in prol…
Browse files Browse the repository at this point in the history
…og rule
  • Loading branch information
A9-dev committed Sep 6, 2024
1 parent b56d483 commit 5a3152d
Show file tree
Hide file tree
Showing 16 changed files with 417 additions and 368 deletions.
6 changes: 1 addition & 5 deletions packages/cahn_demo/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/cahn_demo/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"next": "^14.2.5",
"react": "^18",
"react-dom": "^18",
"schemas": "file:../schemas",
"uuid": "^10.0.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import DeviceTypeInfoTable from "../../components/DeviceTypeInfoTable";
import withAuth from "@/app/utils/withAuth";
import AppBar from "../../components/AppBar";
import { v4 as uuidv4 } from "uuid";
import { device_type_trust } from "@/schemas";
import { device_type_trust, retraction } from "@/schemas";
import TrustSubmissions from "@/app/components/TrustSubmissions";
import initializeWasm from "@/app/utils/initialiseWasm";
import createUnsignedRetractionVC from "@/app/utils/createUnsignedRetractionVC";

const Page = ({ params }) => {
const [deviceTypeData, setDeviceTypeData] = useState({
Expand Down Expand Up @@ -98,36 +99,13 @@ const Page = ({ params }) => {
);
const idToRevoke = response.data.id; // Assuming the API returns an object with an 'id' field

const retractionClaim = {
type: "retraction",
id: `urn:uuid:${uuidv4()}`,
timestamp: Date.now(),
claim_id: idToRevoke,
};

const retractionVC = {
"@context": ["https://www.w3.org/ns/credentials/v2"],
id: `urn:uuid:${uuidv4()}`,
type: ["VerifiableCredential", "UserCredential"],
issuer: `urn:uuid:${uuidv4()}`, // TODO: Use an actual issuer ID?
validFrom: new Date().toISOString(),
credentialSchema: {
id: "https://github.com/nqminds/ClaimCascade/blob/claim_verifier/packages/claim_verifier/user.yaml",
type: "JsonSchema",
},
credentialSubject: retractionClaim,
};

const VC = new window.VerifiableCredential(
retractionVC,
"retraction_schema"
);
const vcToUpload = createUnsignedRetractionVC(idToRevoke);

const privateKeyAsUint8Array = new Uint8Array(
Buffer.from(privateKey, "base64")
);

const signedVc = VC.sign(privateKeyAsUint8Array).to_object();
const signedVc = vcToUpload.sign(privateKeyAsUint8Array).to_object();

const uploadResponse = await axios.post(
"http://localhost:3001/upload/verifiable_credential",
Expand Down
30 changes: 4 additions & 26 deletions packages/cahn_demo/client/src/app/device/[device_id]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import DeviceInfoTable from "../../components/DeviceInfoTable";
import withAuth from "@/app/utils/withAuth";
import { v4 as uuidv4 } from "uuid";
import AppBar from "../../components/AppBar";
import { device_trust } from "@/schemas";
import { device_trust, retraction } from "@/schemas";
import TrustSubmissions from "../../components/TrustSubmissions";
import initializeWasm from "@/app/utils/initialiseWasm";
import createUnsignedRetractionVC from "@/app/utils/createUnsignedRetractionVC";

const Page = ({ params }) => {
const [deviceData, setDeviceData] = useState({
Expand Down Expand Up @@ -126,36 +127,13 @@ const Page = ({ params }) => {
);
const idToRevoke = response.data.id; // Assuming the API returns an object with an 'id' field

const retractionClaim = {
type: "retraction",
id: `urn:uuid:${uuidv4()}`,
timestamp: Date.now(),
claim_id: idToRevoke,
};

const retractionVC = {
"@context": ["https://www.w3.org/ns/credentials/v2"],
id: `urn:uuid:${uuidv4()}`,
type: ["VerifiableCredential", "UserCredential"],
issuer: `urn:uuid:${uuidv4()}`, // TODO: Use an actual issuer ID?
validFrom: new Date().toISOString(),
credentialSchema: {
id: "https://github.com/nqminds/ClaimCascade/blob/claim_verifier/packages/claim_verifier/user.yaml",
type: "JsonSchema",
},
credentialSubject: retractionClaim,
};

const VC = new window.VerifiableCredential(
retractionVC,
"retraction_schema"
);
const vcToUpload = createUnsignedRetractionVC(idToRevoke);

const privateKeyAsUint8Array = new Uint8Array(
Buffer.from(privateKey, "base64")
);

const signedVc = VC.sign(privateKeyAsUint8Array).to_object();
const signedVc = vcToUpload.sign(privateKeyAsUint8Array).to_object();

const uploadResponse = await axios.post(
"http://localhost:3001/upload/verifiable_credential",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import ManufacturerInfoTable from "../../components/ManufacturerInfoTable";
import withAuth from "@/app/utils/withAuth";
import AppBar from "../../components/AppBar";
import { v4 as uuidv4 } from "uuid";
import { manufacturer_trust } from "@/schemas";
import { manufacturer_trust, retraction } from "@/schemas";
import TrustSubmissions from "@/app/components/TrustSubmissions";
import initializeWasm from "@/app/utils/initialiseWasm";
import createUnsignedRetractionVC from "@/app/utils/createUnsignedRetractionVC";

const Page = ({ params }) => {
const [manufacturerData, setManufacturerData] = useState({
Expand Down Expand Up @@ -123,36 +125,13 @@ const Page = ({ params }) => {
);
const idToRevoke = response.data.id; // Assuming the API returns an object with an 'id' field

const retractionClaim = {
type: "retraction",
id: `urn:uuid:${uuidv4()}`,
timestamp: Date.now(),
claim_id: idToRevoke,
};

const retractionVC = {
"@context": ["https://www.w3.org/ns/credentials/v2"],
id: `urn:uuid:${uuidv4()}`,
type: ["VerifiableCredential", "UserCredential"],
issuer: `urn:uuid:${uuidv4()}`, // TODO: Use an actual issuer ID?
validFrom: new Date().toISOString(),
credentialSchema: {
id: "https://github.com/nqminds/ClaimCascade/blob/claim_verifier/packages/claim_verifier/user.yaml",
type: "JsonSchema",
},
credentialSubject: retractionClaim,
};

const VC = new window.VerifiableCredential(
retractionVC,
"retraction_schema"
);
const vcToUpload = createUnsignedRetractionVC(idToRevoke);

const privateKeyAsUint8Array = new Uint8Array(
Buffer.from(privateKey, "base64")
);

const signedVc = VC.sign(privateKeyAsUint8Array).to_object();
const signedVc = vcToUpload.sign(privateKeyAsUint8Array).to_object();

const uploadResponse = await axios.post(
"http://localhost:3001/upload/verifiable_credential",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { retraction } from "@/schemas";
import { v4 as uuidv4 } from "uuid";

const createUnsignedRetractionVC = (idToRevoke) => {
const retractionClaim = {
type: "retraction",
id: `urn:uuid:${uuidv4()}`,
timestamp: Date.now(),
claim_id: idToRevoke,
};

const vc_data = JSON.parse(JSON.stringify(retraction));
vc_data.credentialSubject = retractionClaim;
vc_data.credentialSchema.id =
"https://github.com/nqminds/CAHN/blob/main/packages/schemas/src/retraction.v.1.0.0.schema.yaml";

const vc = new window.VerifiableCredential(
vc_data,
JSON.stringify(retraction)
);

return vc;
};

export default createUnsignedRetractionVC;
2 changes: 2 additions & 0 deletions packages/cahn_demo/client/src/schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const manufacturer_trust = require("./manufacturer_trust.json");
const sbom_vulnerability = require("./sbom_vulnerability.json");
const sbom = require("./sbom.json");
const user = require("./user.json");
const retraction = require("./retraction.json");

module.exports = {
device_trust,
Expand All @@ -26,4 +27,5 @@ module.exports = {
sbom_vulnerability,
sbom,
user,
retraction,
};
44 changes: 44 additions & 0 deletions packages/cahn_demo/client/src/schemas/retraction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"@context": ["https://www.w3.org/ns/credentials/v2"],
"id": "urn:uuid:1cb63635-d3d1-47c1-b653-11e9948ea223",
"type": ["VerifiableCredential", "UserCredential"],
"issuer": "urn:uuid:4e3c2a77-beb1-4ad9-aa8a-c93be6004a7b",
"validFrom": "2024-08-28T14:15:50.312133Z",
"credentialSchema": {
"id": "6924ca71-3c53-4e44-ae03-efb15889f3b5",
"type": "JsonSchema"
},
"credentialSubject": {
"type": "schema",
"id": "f29ba91e-509f-4c87-a239-b1e81afa941c",
"timestamp": 1716131759000,
"schemaName": "retraction",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/nqminds/CAHN/blob/main/packages/schemas/src/device.v.1.0.0.schema.yaml",
"title": "retraction",
"description": "retraction",
"type": "object",
"properties": {
"id": {
"description": "id of the device",
"type": "string"
},
"claim_id": {
"description": "id of the claim that is being retracted",
"type": "string"
},
"timestamp": {
"description": "timestamp at which the retraction was made in milliseconds",
"type": "string"
},
"type": {
"description": "which type of claim is being made",
"type": "string",
"const": "retraction"
}
},
"required": ["id", "claim_id", "timestamp", "type"]
}
}
}
2 changes: 1 addition & 1 deletion packages/cahn_demo/server/emailToPublicKeys.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"henry@nquiringminds.com": [
"9TgqqUgXTTNBuD7qz9vNouf/26IhCucYpivXoUqSvI8="
"0xcwX2RHPNQo1+vzqZJ7dsq8DhYbuLc2hviAjBqTGjw="
]
}
Loading

0 comments on commit 5a3152d

Please sign in to comment.