Skip to content

Commit

Permalink
refactor: mark v3 functions as deprecated (#294)
Browse files Browse the repository at this point in the history
* refactor: mark v3 functions as deprecated

* refactor: mark v3 signDocument as deprecated
  • Loading branch information
HJunyuan authored May 14, 2024
1 parent 70059b2 commit c0ea804
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/3.0/digest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/3.0/obfuscate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ 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)
*/
export const obfuscateVerifiableCredential = (
document: WrappedDocument<OpenAttestationDocument>,
fields: string[] | string
Expand Down
13 changes: 13 additions & 0 deletions src/3.0/salt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,28 @@ 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)
*/
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) => {
Expand Down
3 changes: 3 additions & 0 deletions src/3.0/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T extends OpenAttestationDocument>(
document: SignedWrappedDocument<T> | WrappedDocument<T>,
algorithm: SUPPORTED_SIGNING_ALGORITHM,
Expand Down
3 changes: 3 additions & 0 deletions src/3.0/traverseAndFlatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ interface Options<T> {
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<T>(data: any[], options: Options<T>): T[];
export function traverseAndFlatten<T>(data: string | number | boolean | null, options: Options<T>): T;
export function traverseAndFlatten<T>(data: any, options: Options<T>): T[]; // hmmmm this is probably wrong but it works for the moment :)
Expand Down
36 changes: 36 additions & 0 deletions src/3.0/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<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)
*/
export const VerifiableCredentialWrappedProof = RunTypesRecord({
type: SignatureAlgorithm,
targetHash: String,
Expand All @@ -21,35 +33,59 @@ 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<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)
*/
export const VerifiableCredentialWrappedProofStrict = VerifiableCredentialWrappedProof.And(
RunTypesRecord({
targetHash: OpenAttestationHexString,
merkleRoot: OpenAttestationHexString,
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<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)
*/
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<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)
*/
export type WrappedDocument<T extends OpenAttestationDocumentV3 = OpenAttestationDocumentV3> = 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<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)
*/
export * from "../__generated__/schema.3.0";
3 changes: 3 additions & 0 deletions src/3.0/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <T extends WrappedDocument>(document: T): document is WrappedDocument<T> => {
if (!document.proof) {
return false;
Expand Down
6 changes: 6 additions & 0 deletions src/3.0/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T extends OpenAttestationDocument>(
credential: T,
options: WrapDocumentOptionV3
Expand Down Expand Up @@ -67,6 +70,9 @@ export const wrapDocument = async <T extends OpenAttestationDocument>(
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 <T extends OpenAttestationDocument>(
documents: T[],
options: WrapDocumentOptionV3
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ 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<T extends OpenAttestationDocumentV3>(
data: T,
options?: WrapDocumentOptionV3
): Promise<WrappedDocumentV3<T>> {
return wrapV3Document(data, options ?? { 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 function __unsafe__use__it__at__your__own__risks__wrapDocuments<T extends OpenAttestationDocumentV3>(
dataArray: T[],
options?: WrapDocumentOptionV3
Expand Down Expand Up @@ -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<T extends v3.OpenAttestationDocument>(
document: v3.SignedWrappedDocument<T> | v3.WrappedDocument<T>,
algorithm: SUPPORTED_SIGNING_ALGORITHM,
Expand Down
8 changes: 8 additions & 0 deletions src/shared/@types/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit c0ea804

Please sign in to comment.