@trustvc/trustvc 2.0.3 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,16 +18,28 @@ const w3cCredentialStatusSuspended = /* @__PURE__ */ __name((fragments) => {
18
18
  return issuedFragment?.reason?.code === w3cCredentialStatus.W3CCredentialStatusCode.DOCUMENT_SUSPENDED || issuedFragment?.reason?.code === w3cCredentialStatus.W3CCredentialStatusCode.DOCUMENT_REVOKED_AND_SUSPENDED;
19
19
  }, "w3cCredentialStatusSuspended");
20
20
  const errorMessageHandling = /* @__PURE__ */ __name((fragments) => {
21
+ const { hashValid, issuedValid, identityValid } = tradetrustUtils.interpretFragments(fragments);
21
22
  const errors = [];
22
23
  const isW3cFragments = fragments.some(
23
24
  (f) => f.name.startsWith("W3C") || f.name === "TransferableRecords"
24
25
  );
25
26
  if (isW3cFragments) {
26
- if (w3cCredentialStatusRevoked(fragments)) {
27
- errors.push(tradetrustUtils.CONSTANTS.TYPES.REVOKED);
28
- }
29
- if (w3cCredentialStatusSuspended(fragments)) {
30
- errors.push(tradetrustUtils.CONSTANTS.TYPES.SUSPENDED);
27
+ switch (true) {
28
+ case w3cCredentialStatusRevoked(fragments):
29
+ errors.push(tradetrustUtils.CONSTANTS.TYPES.REVOKED);
30
+ break;
31
+ case w3cCredentialStatusSuspended(fragments):
32
+ errors.push(tradetrustUtils.CONSTANTS.TYPES.SUSPENDED);
33
+ break;
34
+ case !hashValid:
35
+ errors.push(tradetrustUtils.CONSTANTS.TYPES.HASH);
36
+ break;
37
+ case !identityValid:
38
+ errors.push(tradetrustUtils.CONSTANTS.TYPES.IDENTITY);
39
+ break;
40
+ case !issuedValid:
41
+ errors.push(tradetrustUtils.CONSTANTS.TYPES.INVALID);
42
+ break;
31
43
  }
32
44
  return errors;
33
45
  } else return tradetrustUtils.errorMessageHandling(fragments);
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var w3c = require('../../../../w3c');
3
+ var w3cVc = require('@trustvc/w3c-vc');
4
4
 
5
5
  var __defProp = Object.defineProperty;
6
6
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -23,10 +23,11 @@ const w3cEmptyCredentialStatus = {
23
23
  const doc = document;
24
24
  return !!doc.credentialStatus === false || Array.isArray(doc.credentialStatus) && doc.credentialStatus.length === 0 || Object.keys(doc.credentialStatus)?.length === 0;
25
25
  }, "test"),
26
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
26
27
  verify: /* @__PURE__ */ __name(async (document, verifierOptions) => {
27
28
  const doc = document;
28
- const verificationResult = await w3c.verifyW3CSignature(doc, verifierOptions);
29
- if (verificationResult.verified) {
29
+ const verificationResult = w3cVc.isSignedDocument(doc);
30
+ if (verificationResult) {
30
31
  return {
31
32
  type,
32
33
  name,
@@ -39,7 +40,7 @@ const w3cEmptyCredentialStatus = {
39
40
  name,
40
41
  data: false,
41
42
  reason: {
42
- message: verificationResult.error
43
+ message: "Document is not a valid SignedVerifiableCredential"
43
44
  },
44
45
  status: "INVALID"
45
46
  };
@@ -1,4 +1,4 @@
1
- import { CONSTANTS, errorMessageHandling as errorMessageHandling$1 } from '@tradetrust-tt/tradetrust-utils';
1
+ import { interpretFragments, CONSTANTS, errorMessageHandling as errorMessageHandling$1 } from '@tradetrust-tt/tradetrust-utils';
2
2
  export { interpretFragments } from '@tradetrust-tt/tradetrust-utils';
3
3
  import { utils } from '@tradetrust-tt/tt-verify';
4
4
  import { W3CCredentialStatusCode } from '../../verify/fragments/document-status/w3cCredentialStatus';
@@ -17,16 +17,28 @@ const w3cCredentialStatusSuspended = /* @__PURE__ */ __name((fragments) => {
17
17
  return issuedFragment?.reason?.code === W3CCredentialStatusCode.DOCUMENT_SUSPENDED || issuedFragment?.reason?.code === W3CCredentialStatusCode.DOCUMENT_REVOKED_AND_SUSPENDED;
18
18
  }, "w3cCredentialStatusSuspended");
19
19
  const errorMessageHandling = /* @__PURE__ */ __name((fragments) => {
20
+ const { hashValid, issuedValid, identityValid } = interpretFragments(fragments);
20
21
  const errors = [];
21
22
  const isW3cFragments = fragments.some(
22
23
  (f) => f.name.startsWith("W3C") || f.name === "TransferableRecords"
23
24
  );
24
25
  if (isW3cFragments) {
25
- if (w3cCredentialStatusRevoked(fragments)) {
26
- errors.push(CONSTANTS.TYPES.REVOKED);
27
- }
28
- if (w3cCredentialStatusSuspended(fragments)) {
29
- errors.push(CONSTANTS.TYPES.SUSPENDED);
26
+ switch (true) {
27
+ case w3cCredentialStatusRevoked(fragments):
28
+ errors.push(CONSTANTS.TYPES.REVOKED);
29
+ break;
30
+ case w3cCredentialStatusSuspended(fragments):
31
+ errors.push(CONSTANTS.TYPES.SUSPENDED);
32
+ break;
33
+ case !hashValid:
34
+ errors.push(CONSTANTS.TYPES.HASH);
35
+ break;
36
+ case !identityValid:
37
+ errors.push(CONSTANTS.TYPES.IDENTITY);
38
+ break;
39
+ case !issuedValid:
40
+ errors.push(CONSTANTS.TYPES.INVALID);
41
+ break;
30
42
  }
31
43
  return errors;
32
44
  } else return errorMessageHandling$1(fragments);
@@ -1,4 +1,4 @@
1
- import { verifyW3CSignature } from '../../../../w3c';
1
+ import { isSignedDocument } from '@trustvc/w3c-vc';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -21,10 +21,11 @@ const w3cEmptyCredentialStatus = {
21
21
  const doc = document;
22
22
  return !!doc.credentialStatus === false || Array.isArray(doc.credentialStatus) && doc.credentialStatus.length === 0 || Object.keys(doc.credentialStatus)?.length === 0;
23
23
  }, "test"),
24
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
24
25
  verify: /* @__PURE__ */ __name(async (document, verifierOptions) => {
25
26
  const doc = document;
26
- const verificationResult = await verifyW3CSignature(doc, verifierOptions);
27
- if (verificationResult.verified) {
27
+ const verificationResult = isSignedDocument(doc);
28
+ if (verificationResult) {
28
29
  return {
29
30
  type,
30
31
  name,
@@ -37,7 +38,7 @@ const w3cEmptyCredentialStatus = {
37
38
  name,
38
39
  data: false,
39
40
  reason: {
40
- message: verificationResult.error
41
+ message: "Document is not a valid SignedVerifiableCredential"
41
42
  },
42
43
  status: "INVALID"
43
44
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustvc/trustvc",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "TrustVC library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -10,6 +10,7 @@
10
10
  ],
11
11
  "scripts": {
12
12
  "test": "npx vitest --run --test-timeout=15000",
13
+ "test:watch": "npx vitest --test-timeout=15000",
13
14
  "test:e2e": "concurrently -k \"npm run e2e:node\" \"npm run wait-and-test\"",
14
15
  "e2e:node": "npx hardhat node",
15
16
  "wait-and-test": "wait-on tcp:8545 && npm run e2e:test",