Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow both OA and W3C VCs to be digested or signed #317

Open
wants to merge 4 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions scripts/generateV4JsonSchemas.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs";
import path from "path";
import { zodToJsonSchema } from "zod-to-json-schema";
import { V4OpenAttestationDocument, V4WrappedDocument, V4SignedWrappedDocument } from "../src/4.0/types";
import { OAVerifiableCredential, DigestedOAVerifiableCredential, SignedOAVerifiableCredential } from "../src/4.0/types";

const OUTPUT_DIR = path.resolve("./src/4.0/jsonSchemas/__generated__");

Expand All @@ -13,19 +13,19 @@ fs.mkdirSync(OUTPUT_DIR, { recursive: true });

const ZOD_SCHEMAS = [
{
filename: "v4-document.schema.json",
schemaName: "v4Document",
zodSchema: V4OpenAttestationDocument,
filename: "v4-oa-vc.schema.json",
schemaName: "OAVerifiableCredential",
zodSchema: OAVerifiableCredential,
},
{
filename: "v4-wrapped-document.schema.json",
schemaName: "v4WrappedDocument",
zodSchema: V4WrappedDocument,
filename: "v4-digested-oa-vc.schema.json",
schemaName: "DigestedOAVerifiableCredential",
zodSchema: DigestedOAVerifiableCredential,
},
{
filename: "v4-signed-wrapped-document.schema.json",
schemaName: "v4SignedWrappedDocument",
zodSchema: V4SignedWrappedDocument,
filename: "v4-signed-oa-vc.schema.json",
schemaName: "SignedOAVerifiableCredential",
zodSchema: SignedOAVerifiableCredential,
},
];

Expand Down
2 changes: 1 addition & 1 deletion src/3.0/digest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Salt } from "./types";
import { OpenAttestationDocument } from "../__generated__/schema.3.0";

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const digestCredential = (document: OpenAttestationDocument, salts: Salt[], obfuscatedData: string[]) => {
// Prepare array of hashes from visible data
Expand Down
2 changes: 1 addition & 1 deletion src/3.0/obfuscate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const obfuscate = (_data: WrappedDocument<OpenAttestationDocument>, fields: stri
};

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const obfuscateVerifiableCredential = (
document: WrappedDocument<OpenAttestationDocument>,
Expand Down
8 changes: 4 additions & 4 deletions src/3.0/salt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ const illegalCharactersCheck = (data: Record<string, any>) => {
// Using 32 bytes of entropy as compared to 16 bytes in uuid
// Using hex encoding as compared to base64 for constant string length
/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const secureRandomString = () => randomBytes(ENTROPY_IN_BYTES).toString("hex");

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const salt = (data: any): Salt[] => {
// Check for illegal characters e.g. '.', '[' or ']'
Expand All @@ -36,12 +36,12 @@ export const salt = (data: any): Salt[] => {
};

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const encodeSalt = (salts: Salt[]): string => Base64.encode(JSON.stringify(salts));

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const decodeSalt = (salts: string): Salt[] => {
const decoded: Salt[] = JSON.parse(Base64.decode(salts));
Expand Down
2 changes: 1 addition & 1 deletion src/3.0/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isSignedWrappedV3Document } from "../shared/utils";
import { Signer } from "@ethersproject/abstract-signer";

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const signDocument = async <T extends OpenAttestationDocument>(
document: SignedWrappedDocument<T> | WrappedDocument<T>,
Expand Down
2 changes: 1 addition & 1 deletion src/3.0/traverseAndFlatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface Options<T> {
}

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export function traverseAndFlatten<T>(data: any[], options: Options<T>): T[];
export function traverseAndFlatten<T>(data: string | number | boolean | null, options: Options<T>): T;
Expand Down
24 changes: 12 additions & 12 deletions src/3.0/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import { OpenAttestationHexString, ProofPurpose, SchemaId, SignatureAlgorithm }
import { Array as RunTypesArray, Record as RunTypesRecord, Static, String } from "runtypes";

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export interface Salt {
value: string;
path: string;
}
/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const ObfuscationMetadata = RunTypesRecord({
obfuscated: RunTypesArray(OpenAttestationHexString),
});
/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export type ObfuscationMetadata = Static<typeof ObfuscationMetadata>;

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const VerifiableCredentialWrappedProof = RunTypesRecord({
type: SignatureAlgorithm,
Expand All @@ -34,11 +34,11 @@ export const VerifiableCredentialWrappedProof = RunTypesRecord({
proofPurpose: ProofPurpose,
});
/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export type VerifiableCredentialWrappedProof = Static<typeof VerifiableCredentialWrappedProof>;
/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const VerifiableCredentialWrappedProofStrict = VerifiableCredentialWrappedProof.And(
RunTypesRecord({
Expand All @@ -48,12 +48,12 @@ export const VerifiableCredentialWrappedProofStrict = VerifiableCredentialWrappe
})
);
/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export type VerifiableCredentialWrappedProofStrict = Static<typeof VerifiableCredentialWrappedProofStrict>;

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const VerifiableCredentialSignedProof = VerifiableCredentialWrappedProof.And(
RunTypesRecord({
Expand All @@ -62,14 +62,14 @@ export const VerifiableCredentialSignedProof = VerifiableCredentialWrappedProof.
})
);
/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export type VerifiableCredentialSignedProof = Static<typeof VerifiableCredentialSignedProof>;

// TODO rename to something else that is not proof to allow for did-signed documents
// Also it makes sense to use `proof` to denote a document that has been issued
/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export type WrappedDocument<T extends OpenAttestationDocumentV3 = OpenAttestationDocumentV3> = T & {
version: SchemaId.v3;
Expand All @@ -78,14 +78,14 @@ export type WrappedDocument<T extends OpenAttestationDocumentV3 = OpenAttestatio
};

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export type SignedWrappedDocument<T extends OpenAttestationDocumentV3 = OpenAttestationDocumentV3> =
WrappedDocument<T> & {
proof: VerifiableCredentialSignedProof;
};

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export * from "../__generated__/schema.3.0";
2 changes: 1 addition & 1 deletion src/3.0/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { checkProof } from "../shared/merkle";
import { decodeSalt, salt } from "./salt";

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const verify = <T extends WrappedDocument>(document: T): document is WrappedDocument<T> => {
if (!document.proof) {
Expand Down
4 changes: 2 additions & 2 deletions src/3.0/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getSchema } from "../shared/ajv";
const getExternalSchema = (schema?: string) => (schema ? { schema } : {});

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const wrapDocument = async <T extends OpenAttestationDocument>(
credential: T,
Expand Down Expand Up @@ -71,7 +71,7 @@ export const wrapDocument = async <T extends OpenAttestationDocument>(
};

/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/beta)
*/
export const wrapDocuments = async <T extends OpenAttestationDocument>(
documents: T[],
Expand Down
Loading
Loading