import React, { useState } from "react"; import styled from "styled-components"; import { Link, Flex, Box, Text, Button } from "rimble-ui"; import { LinkIcon, Send } from "@rimble/icons"; import { SchemaDataResponse, SchemaDataInput } from "./types"; import { H5 } from "../../layouts/LayoutComponents"; import { fonts } from "../../../themes"; import { CopyableTruncatableText } from "../../elements/CopyableTruncatableText/CopyableTruncatableText"; import { HighlightedJson } from "../../elements/HighlightedJson/HighlightedJson"; import { Tabs } from "../../layouts/Tabs/Tabs"; import { ModalContent, ModalWithX } from "../../elements/Modals"; import { PopupGroup } from "../../elements/Popup/Popup"; import { getLdTypesFromSchemaResponse, getSchemaUris } from "./utils"; import { links } from "../../../config"; const StyledTabs = styled(Tabs)` li:first-child { margin-left: 0; } li:last-child { margin-right: 0; } `; const StyledLink: React.FC = (props) => ; export interface SchemaUsageProps { schema: SchemaDataResponse | SchemaDataInput; style?: any; } export const SchemaUsage: React.FunctionComponent = (props) => { const { schema } = props; const [urlTab, setUrlTab] = useState("jsonLd"); const [issueTab, setIssueTab] = useState("sertoAgent"); const [infoModalOpen, setInfoModalOpen] = useState(false); const [exampleVcModalOpen, setExampleVcModalOpen] = useState(false); const uris = getSchemaUris(schema); const { subjectLdType, credLdType } = getLdTypesFromSchemaResponse(schema); // @TODO/tobek Need a more elegant way to do this, probably VcSchema library should have a utility that creates an example VC that actually has all the fields filled in based on schema. const exampleVc = { "@context": ["https://www.w3.org/2018/credentials/v1", ...(uris?.jsonLdContext ? [uris.jsonLdContext] : [])], ...(uris?.jsonSchema && { credentialSchema: { id: uris.jsonSchema, type: "JsonSchemaValidator2018", }, }), type: ["VerifiableCredential", ...(credLdType ? [credLdType] : [])], issuer: "[ISSUER]", issuanceDate: "[DATE]", credentialSubject: { ...(subjectLdType ? { type: subjectLdType } : {}), id: "[SUBJECT]", "...": "...", }, }; return (
Schema URLs
setUrlTab(tabName)} titleFontSize={1} tabs={[ { tabName: "jsonLd", title: "JSON-LD Context", content: ( setInfoModalOpen(true)}> Learn more about JSON-LD Context ), }, { tabName: "jsonSchema", title: "JSON Schema", content: ( setInfoModalOpen(true)}> Learn more about JSON Schema ), }, ]} />
Issue Verifiable Credentials
setIssueTab(tabName)} titleFontSize={1} tabs={[ { tabName: "sertoAgent", title: "Use Serto Agent", content: ( Use Serto Agent, our user-friendly admin tool, to issue VCs. Issue VC with Serto Agent ), }, { tabName: "manual", title: "Manually", content: ( Use your own agent, like{" "} Veramo , to issue VCs manually. setExampleVcModalOpen(true)}> View example VC for this schema ), }, ]} />
setInfoModalOpen(false)} width={9}> e.stopPropagation()}> JSON-LD contexts ( specification ) are JSON data that define data relationships and semantics, and can leverage property and entity types on schema repositories such as{" "} schema.org . For more details on using JSON-LD contexts in VCs, see{" "} the contexts section of the VC spec . JSON Schema ( specification ) schemas are also JSON data, but define data structure, requirements, descriptions and other metadata, thereby supporting validation of VCs to ensure conformance. For more details on using JSON Schemas in VCs, see{" "} the credentialSchema field in the VC spec . setExampleVcModalOpen(false)} width={10}> e.stopPropagation()}>
); };