Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
yanlow committed Sep 10, 2024
1 parent 272e149 commit fb1a8eb
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 32 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
}
},
"prettier": {
"printWidth": 120
"printWidth": 120,
"trailingComma": "es5"
},
"snyk": true
}
35 changes: 14 additions & 21 deletions scripts/generate.v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ const generateDnsDid = async () => {
},
},
};
const wrappedInvalidDnsDidDocument = await __unsafe__use__it__at__your__own__risks__wrapDocument(
validSignatureWithoutDnsTxt
);
const wrappedInvalidDnsDidDocument =
await __unsafe__use__it__at__your__own__risks__wrapDocument(validSignatureWithoutDnsTxt);
const signatureForInvalidDocument = await signMerkleRoot(`0x${wrappedInvalidDnsDidDocument.proof.merkleRoot}`);
const signedInvalidDnsDidDocument: v3.SignedWrappedDocument = {
...wrappedInvalidDnsDidDocument,
Expand Down Expand Up @@ -176,9 +175,8 @@ const generateDid = async () => {
},
},
};
const wrappedInvalidDnsDidDocument = await __unsafe__use__it__at__your__own__risks__wrapDocument(
validSignatureWithoutDnsTxt
);
const wrappedInvalidDnsDidDocument =
await __unsafe__use__it__at__your__own__risks__wrapDocument(validSignatureWithoutDnsTxt);
const signatureForInvalidDocument = await signMerkleRoot(`0x${wrappedInvalidDnsDidDocument.proof.merkleRoot}`);
const signedInvalidDnsDidDocument: v3.SignedWrappedDocument = {
...wrappedInvalidDnsDidDocument,
Expand All @@ -194,23 +192,20 @@ const generateDid = async () => {
const generateDocumentStore = async () => {
info("Generating Document Store files");
writeFileSync("./test/fixtures/v3/documentStore.json", JSON.stringify(baseDocumentStoreDocument, null, 2));
const wrappedBaseDocumentStoreDocument = await __unsafe__use__it__at__your__own__risks__wrapDocument(
baseDocumentStoreDocument
);
const wrappedBaseDocumentStoreDocument =
await __unsafe__use__it__at__your__own__risks__wrapDocument(baseDocumentStoreDocument);
writeFileSync(
"./test/fixtures/v3/documentStore-wrapped.json",
JSON.stringify(wrappedBaseDocumentStoreDocument, null, 2)
);
const issuedBaseDocumentStoreDocument = await __unsafe__use__it__at__your__own__risks__wrapDocument(
baseDocumentStoreDocument
);
const issuedBaseDocumentStoreDocument =
await __unsafe__use__it__at__your__own__risks__wrapDocument(baseDocumentStoreDocument);
writeFileSync(
"./test/fixtures/v3/documentStore-issued.json",
JSON.stringify(issuedBaseDocumentStoreDocument, null, 2)
);
const revokedBaseDocumentStoreDocument = await __unsafe__use__it__at__your__own__risks__wrapDocument(
baseDocumentStoreDocument
);
const revokedBaseDocumentStoreDocument =
await __unsafe__use__it__at__your__own__risks__wrapDocument(baseDocumentStoreDocument);
writeFileSync(
"./test/fixtures/v3/documentStore-revoked.json",
JSON.stringify(revokedBaseDocumentStoreDocument, null, 2)
Expand Down Expand Up @@ -246,16 +241,14 @@ const generateDocumentStore = async () => {
const generateTokenRegistry = async () => {
info("Generating Token Registry files");
writeFileSync("./test/fixtures/v3/tokenRegistry.json", JSON.stringify(baseTokenRegistryDocument, null, 2));
const wrappedBaseTokenRegistryDocument = await __unsafe__use__it__at__your__own__risks__wrapDocument(
baseTokenRegistryDocument
);
const wrappedBaseTokenRegistryDocument =
await __unsafe__use__it__at__your__own__risks__wrapDocument(baseTokenRegistryDocument);
writeFileSync(
"./test/fixtures/v3/tokenRegistry-wrapped.json",
JSON.stringify(wrappedBaseTokenRegistryDocument, null, 2)
);
const issuedBaseTokenRegistryDocument = await __unsafe__use__it__at__your__own__risks__wrapDocument(
baseTokenRegistryDocument
);
const issuedBaseTokenRegistryDocument =
await __unsafe__use__it__at__your__own__risks__wrapDocument(baseTokenRegistryDocument);
writeFileSync(
"./test/fixtures/v3/tokenRegistry-issued.json",
JSON.stringify(issuedBaseTokenRegistryDocument, null, 2)
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ describe("generateProvider", () => {
const options = { apiKey: "abc123" } as ProviderDetails;
expect(() => {
generateProvider(options);
}).toThrowError(
}).toThrow(
"We could not link the apiKey provided to a provider, please state the provider to use in the parameter."
);
});

it("should throw an error when if process.env is using the wrong value for PROVIDER", () => {
process.env.PROVIDER_ENDPOINT_TYPE = "ABC";
expect(() => generateProvider()).toThrowError(
expect(() => generateProvider()).toThrow(
"The provider provided is not on the list of providers. Please use one of the following: infura, alchemy or jsonrpc."
);
});
Expand Down
4 changes: 2 additions & 2 deletions src/getIdentifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const malformedVerificationFragment2: ValidVerificationFragment<undefined> = {

describe("getIdentifier", () => {
it("should throw an error when no fragments are provided", () => {
expect(() => getIdentifier([])).toThrowError("Please provide at least one verification fragment");
expect(() => getIdentifier([])).toThrow("Please provide at least one verification fragment");
});
it("should return an unknown identity proof, when fragment.name is out of specification", () => {
expect(getIdentifier([verificationFragment1, malformedVerificationFragment1])).toStrictEqual({
Expand All @@ -97,7 +97,7 @@ describe("getIdentifier", () => {
});
});
it("should throw an error when fragment.data cannot be handled", () => {
expect(() => getIdentifier([verificationFragment1, malformedVerificationFragment2])).toThrowError(
expect(() => getIdentifier([verificationFragment1, malformedVerificationFragment2])).toThrow(
"No data property found in fragment, malformed fragment"
);
});
Expand Down
4 changes: 2 additions & 2 deletions src/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { VerificationFragment } from "./types/core";

describe("isValid", () => {
it("should throw an error when no fragments are provided", () => {
expect(() => isValid([])).toThrowError("Please provide at least one verification fragment to check");
expect(() => isValid([])).toThrow("Please provide at least one verification fragment to check");
});
it("should throw an error when empty types are provided", () => {
const verificationFragment: VerificationFragment = {
status: "VALID",
name: "any",
type: "DOCUMENT_STATUS",
};
expect(() => isValid([verificationFragment], [])).toThrowError("Please provide at least one type to check");
expect(() => isValid([verificationFragment], [])).toThrow("Please provide at least one type to check");
});

describe("with one provided type", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ const verifyV3 = async (
const reason = InvalidDidSignedIssuanceStatus.guard(verificationResult)
? verificationResult.reason
: InvalidRevocationStatus.guard(revocationStatus)
? revocationStatus.reason
: undefined;
? revocationStatus.reason
: undefined;
if (!reason) {
throw new CodedError(
"Unable to retrieve the reason of the failure",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const isMissingTokenRegistry = (error: any) => {
);
};
const decodeError = (error: any) => {
const reason = error.reason && Array.isArray(error.reason) ? error.reason[0] : error.reason ?? "";
const reason = error.reason && Array.isArray(error.reason) ? error.reason[0] : (error.reason ?? "");
switch (true) {
case isNonExistentToken(error):
return `Document has not been issued under token registry`;
Expand Down
2 changes: 1 addition & 1 deletion src/verifiers/documentStatus/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const getIntermediateHashes = (targetHash: Hash, proofs: Hash[] = []) =>
* In case where we cannot tell, we throw an error
* */
export const decodeError = (error: any) => {
const reason = error.reason && Array.isArray(error.reason) ? error.reason[0] : error.reason ?? "";
const reason = error.reason && Array.isArray(error.reason) ? error.reason[0] : (error.reason ?? "");
switch (true) {
case !error.reason &&
(error.method?.toLowerCase() === "isRevoked(bytes32)".toLowerCase() ||
Expand Down

0 comments on commit fb1a8eb

Please sign in to comment.