From c0ea804ab835f33ce37a66a95cf2a41129129d5e Mon Sep 17 00:00:00 2001 From: Kyle Huang Junyuan Date: Tue, 14 May 2024 15:42:59 +0800 Subject: [PATCH 1/2] refactor: mark v3 functions as deprecated (#294) * refactor: mark v3 functions as deprecated * refactor: mark v3 signDocument as deprecated --- src/3.0/digest.ts | 3 +++ src/3.0/obfuscate.ts | 3 +++ src/3.0/salt.ts | 13 +++++++++++++ src/3.0/sign.ts | 3 +++ src/3.0/traverseAndFlatten.ts | 3 +++ src/3.0/types.ts | 36 +++++++++++++++++++++++++++++++++++ src/3.0/verify.ts | 3 +++ src/3.0/wrap.ts | 6 ++++++ src/index.ts | 9 +++++++++ src/shared/@types/wrap.ts | 8 ++++++++ 10 files changed, 87 insertions(+) diff --git a/src/3.0/digest.ts b/src/3.0/digest.ts index 436dd0a3..11020d2f 100644 --- a/src/3.0/digest.ts +++ b/src/3.0/digest.ts @@ -3,6 +3,9 @@ import { keccak256 } from "js-sha3"; 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) + */ export const digestCredential = (document: OpenAttestationDocument, salts: Salt[], obfuscatedData: string[]) => { // Prepare array of hashes from visible data const hashedUnhashedDataArray = salts diff --git a/src/3.0/obfuscate.ts b/src/3.0/obfuscate.ts index 994880c1..cdcf36b3 100644 --- a/src/3.0/obfuscate.ts +++ b/src/3.0/obfuscate.ts @@ -37,6 +37,9 @@ const obfuscate = (_data: WrappedDocument, 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) + */ export const obfuscateVerifiableCredential = ( document: WrappedDocument, fields: string[] | string diff --git a/src/3.0/salt.ts b/src/3.0/salt.ts index ab4a5a33..edd75b43 100644 --- a/src/3.0/salt.ts +++ b/src/3.0/salt.ts @@ -21,15 +21,28 @@ const illegalCharactersCheck = (data: Record) => { // 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) + */ 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) + */ export const salt = (data: any): Salt[] => { // Check for illegal characters e.g. '.', '[' or ']' illegalCharactersCheck(data); return traverseAndFlatten(data, { iteratee: ({ path }) => ({ value: secureRandomString(), path }) }); }; +/** + * @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) + */ 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) + */ export const decodeSalt = (salts: string): Salt[] => { const decoded: Salt[] = JSON.parse(Base64.decode(salts)); decoded.forEach((salt) => { diff --git a/src/3.0/sign.ts b/src/3.0/sign.ts index 8f8fd6f1..597c9c18 100644 --- a/src/3.0/sign.ts +++ b/src/3.0/sign.ts @@ -9,6 +9,9 @@ import { SigningKey, SUPPORTED_SIGNING_ALGORITHM } from "../shared/@types/sign"; import { isSignedWrappedV3Document } from "../shared/utils"; import { ethers } from "ethers"; +/** + * @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) + */ export const signDocument = async ( document: SignedWrappedDocument | WrappedDocument, algorithm: SUPPORTED_SIGNING_ALGORITHM, diff --git a/src/3.0/traverseAndFlatten.ts b/src/3.0/traverseAndFlatten.ts index d5a855ad..3b8bae97 100644 --- a/src/3.0/traverseAndFlatten.ts +++ b/src/3.0/traverseAndFlatten.ts @@ -7,6 +7,9 @@ interface Options { 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) + */ export function traverseAndFlatten(data: any[], options: Options): T[]; export function traverseAndFlatten(data: string | number | boolean | null, options: Options): T; export function traverseAndFlatten(data: any, options: Options): T[]; // hmmmm this is probably wrong but it works for the moment :) diff --git a/src/3.0/types.ts b/src/3.0/types.ts index c4df35ed..884df64a 100644 --- a/src/3.0/types.ts +++ b/src/3.0/types.ts @@ -3,15 +3,27 @@ import { OpenAttestationDocument as OpenAttestationDocumentV3 } from "../__gener import { OpenAttestationHexString, ProofPurpose, SchemaId, SignatureAlgorithm } from "../shared/@types/document"; 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) + */ 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) + */ 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) + */ export type ObfuscationMetadata = Static; +/** + * @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) + */ export const VerifiableCredentialWrappedProof = RunTypesRecord({ type: SignatureAlgorithm, targetHash: String, @@ -21,7 +33,13 @@ export const VerifiableCredentialWrappedProof = RunTypesRecord({ privacy: ObfuscationMetadata, 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) + */ export type VerifiableCredentialWrappedProof = Static; +/** + * @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) + */ export const VerifiableCredentialWrappedProofStrict = VerifiableCredentialWrappedProof.And( RunTypesRecord({ targetHash: OpenAttestationHexString, @@ -29,27 +47,45 @@ export const VerifiableCredentialWrappedProofStrict = VerifiableCredentialWrappe proofs: 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) + */ export type VerifiableCredentialWrappedProofStrict = Static; +/** + * @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) + */ export const VerifiableCredentialSignedProof = VerifiableCredentialWrappedProof.And( RunTypesRecord({ key: String, signature: 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) + */ export type VerifiableCredentialSignedProof = Static; // 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) + */ export type WrappedDocument = T & { version: SchemaId.v3; schema?: string; proof: 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) + */ export type SignedWrappedDocument = WrappedDocument & { 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) + */ export * from "../__generated__/schema.3.0"; diff --git a/src/3.0/verify.ts b/src/3.0/verify.ts index ac413a25..bb0eb1b0 100644 --- a/src/3.0/verify.ts +++ b/src/3.0/verify.ts @@ -3,6 +3,9 @@ import { digestCredential } from "./digest"; 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) + */ export const verify = (document: T): document is WrappedDocument => { if (!document.proof) { return false; diff --git a/src/3.0/wrap.ts b/src/3.0/wrap.ts index a13901ae..661f9f0a 100644 --- a/src/3.0/wrap.ts +++ b/src/3.0/wrap.ts @@ -12,6 +12,9 @@ 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) + */ export const wrapDocument = async ( credential: T, options: WrapDocumentOptionV3 @@ -67,6 +70,9 @@ export const wrapDocument = async ( return verifiableCredential; }; +/** + * @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) + */ export const wrapDocuments = async ( documents: T[], options: WrapDocumentOptionV3 diff --git a/src/index.ts b/src/index.ts index 9000cb6e..c5374da8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,6 +21,9 @@ import { SigningKey, SUPPORTED_SIGNING_ALGORITHM } from "./shared/@types/sign"; import { ethers, Signer } from "ethers"; import { getSchema } from "./shared/ajv"; +/** + * @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) + */ export function __unsafe__use__it__at__your__own__risks__wrapDocument( data: T, options?: WrapDocumentOptionV3 @@ -28,6 +31,9 @@ export function __unsafe__use__it__at__your__own__risks__wrapDocument( dataArray: T[], options?: WrapDocumentOptionV3 @@ -75,6 +81,9 @@ export const isSchemaValidationError = (error: any): error is SchemaValidationEr return !!error.validationErrors; }; +/** + * @deprecated signing of v3 documents 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) + */ export async function signDocument( document: v3.SignedWrappedDocument | v3.WrappedDocument, algorithm: SUPPORTED_SIGNING_ALGORITHM, diff --git a/src/shared/@types/wrap.ts b/src/shared/@types/wrap.ts index 8ca61b8d..7e24fc8f 100644 --- a/src/shared/@types/wrap.ts +++ b/src/shared/@types/wrap.ts @@ -4,15 +4,23 @@ export interface WrapDocumentOption { externalSchemaId?: string; version?: SchemaId; } + export interface WrapDocumentOptionV2 { externalSchemaId?: string; version?: SchemaId.v2; } + +/** + * @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) + */ export interface WrapDocumentOptionV3 { externalSchemaId?: string; version: SchemaId.v3; } +/** + * @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) + */ export const isWrapDocumentOptionV3 = (options: any): options is WrapDocumentOptionV3 => { return options?.version === SchemaId.v3; }; From 7600e49880ab5f87ac20259675add7e656719530 Mon Sep 17 00:00:00 2001 From: Kyle Huang Junyuan Date: Tue, 14 May 2024 15:53:04 +0800 Subject: [PATCH 2/2] fix: mark v3 functions as deprecated (#296) * Revert "refactor: mark v3 functions as deprecated (#294)" This reverts commit c0ea804ab835f33ce37a66a95cf2a41129129d5e. * refactor: mark v3 functions as deprecated * refactor: mark v3 signDocument as deprecated