@trustvc/trustvc 1.0.4 → 1.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.
- package/dist/esm/verify/fragments/document-status/transferableRecords/transferableRecordVerifier.js +33 -30
- package/dist/esm/verify/fragments/document-status/w3cCredentialStatus.js +20 -10
- package/dist/verify/fragments/document-status/transferableRecords/transferableRecordVerifier.js +33 -30
- package/dist/verify/fragments/document-status/transferableRecords/transferableRecordVerifier.types.d.mts +1 -9
- package/dist/verify/fragments/document-status/transferableRecords/transferableRecordVerifier.types.d.ts +1 -9
- package/dist/verify/fragments/document-status/w3cCredentialStatus.js +19 -9
- package/package.json +7 -7
package/dist/esm/verify/fragments/document-status/transferableRecords/transferableRecordVerifier.js
CHANGED
|
@@ -8,45 +8,46 @@ const TRANSFERABLE_RECORDS_TYPE = "TransferableRecords";
|
|
|
8
8
|
const type = "DOCUMENT_STATUS";
|
|
9
9
|
const name = TRANSFERABLE_RECORDS_TYPE;
|
|
10
10
|
const verify = /* @__PURE__ */ __name(async (document, options) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (w3cVC.isSignedDocument(document)) {
|
|
14
|
-
signedDocument = document;
|
|
15
|
-
tokenId = "0x" + signedDocument?.credentialStatus?.tokenId;
|
|
16
|
-
}
|
|
17
|
-
const credentialStatus = signedDocument?.credentialStatus;
|
|
18
|
-
if (!credentialStatus?.tokenRegistry) {
|
|
19
|
-
throw new CodedError(
|
|
20
|
-
"Document's credentialStatus does not have tokenRegistry",
|
|
21
|
-
OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT,
|
|
22
|
-
OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
if (!credentialStatus?.tokenNetwork || !credentialStatus?.tokenNetwork?.chainId) {
|
|
26
|
-
throw new CodedError(
|
|
27
|
-
"Document's credentialStatus does not have tokenNetwork.chainId",
|
|
28
|
-
OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT,
|
|
29
|
-
OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]
|
|
30
|
-
);
|
|
31
|
-
}
|
|
11
|
+
const signedDocument = document;
|
|
12
|
+
const credentialStatuses = Array.isArray(signedDocument?.credentialStatus) ? signedDocument?.credentialStatus : [signedDocument?.credentialStatus];
|
|
32
13
|
const { provider } = options;
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
14
|
+
const verificationResult = await Promise.all(
|
|
15
|
+
credentialStatuses.map(async (credentialStatus) => {
|
|
16
|
+
const tokenId = "0x" + credentialStatus.tokenId;
|
|
17
|
+
if (!credentialStatus?.tokenRegistry) {
|
|
18
|
+
throw new CodedError(
|
|
19
|
+
"Document's credentialStatus does not have tokenRegistry",
|
|
20
|
+
OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT,
|
|
21
|
+
OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
if (!credentialStatus?.tokenNetwork || !credentialStatus?.tokenNetwork?.chainId) {
|
|
25
|
+
throw new CodedError(
|
|
26
|
+
"Document's credentialStatus does not have tokenNetwork.chainId",
|
|
27
|
+
OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT,
|
|
28
|
+
OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
const mintStatus = await isTokenMintedOnRegistry({
|
|
32
|
+
tokenRegistryAddress: credentialStatus?.tokenRegistry,
|
|
33
|
+
tokenId,
|
|
34
|
+
provider
|
|
35
|
+
});
|
|
36
|
+
return mintStatus;
|
|
37
|
+
})
|
|
38
|
+
);
|
|
38
39
|
const result = {
|
|
39
40
|
name,
|
|
40
41
|
type,
|
|
41
42
|
status: "INVALID",
|
|
42
43
|
data: {
|
|
43
|
-
tokenRegistry:
|
|
44
|
+
tokenRegistry: credentialStatuses?.[0]?.tokenRegistry
|
|
44
45
|
}
|
|
45
46
|
};
|
|
46
|
-
if (ValidTokenRegistryStatus.guard
|
|
47
|
+
if (verificationResult.every(ValidTokenRegistryStatus.guard)) {
|
|
47
48
|
result.status = "VALID";
|
|
48
49
|
} else {
|
|
49
|
-
result.reason =
|
|
50
|
+
result.reason = verificationResult?.[0]?.reason;
|
|
50
51
|
}
|
|
51
52
|
return result;
|
|
52
53
|
}, "verify");
|
|
@@ -63,7 +64,9 @@ const skip = /* @__PURE__ */ __name(async () => {
|
|
|
63
64
|
};
|
|
64
65
|
}, "skip");
|
|
65
66
|
const test = /* @__PURE__ */ __name((document) => {
|
|
66
|
-
|
|
67
|
+
const doc = document;
|
|
68
|
+
const credentialStatuses = Array.isArray(doc?.credentialStatus) ? doc?.credentialStatus : [doc?.credentialStatus];
|
|
69
|
+
if (w3cVC.isSignedDocument(document) && credentialStatuses.every((cs) => cs?.type === TRANSFERABLE_RECORDS_TYPE)) {
|
|
67
70
|
return true;
|
|
68
71
|
}
|
|
69
72
|
return false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { verifyCredentialStatus } from '@trustvc/w3c-vc';
|
|
1
|
+
import { isSignedDocument, verifyCredentialStatus } from '@trustvc/w3c-vc';
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -17,33 +17,43 @@ const w3cCredentialStatus = {
|
|
|
17
17
|
}, "skip"),
|
|
18
18
|
test: /* @__PURE__ */ __name((document) => {
|
|
19
19
|
const doc = document;
|
|
20
|
-
|
|
20
|
+
const credentialStatuses = Array.isArray(doc?.credentialStatus) ? doc?.credentialStatus : [doc?.credentialStatus];
|
|
21
|
+
const test = /* @__PURE__ */ __name((credentialStatus) => ["BitstringStatusListEntry", "StatusList2021Entry"].includes(credentialStatus?.type), "test");
|
|
22
|
+
if (isSignedDocument(document) && credentialStatuses.every(test)) {
|
|
23
|
+
return true;
|
|
24
|
+
} else {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
21
27
|
}, "test"),
|
|
22
28
|
verify: /* @__PURE__ */ __name(async (document) => {
|
|
23
29
|
const doc = document;
|
|
24
|
-
const
|
|
25
|
-
|
|
30
|
+
const credentialStatuses = Array.isArray(doc.credentialStatus) ? doc.credentialStatus : [doc.credentialStatus];
|
|
31
|
+
const verificationResult = await Promise.all(
|
|
32
|
+
credentialStatuses.map((cs) => verifyCredentialStatus(cs, cs?.type))
|
|
33
|
+
);
|
|
34
|
+
if (verificationResult.some((r) => r.error)) {
|
|
26
35
|
return {
|
|
27
36
|
type: "DOCUMENT_STATUS",
|
|
28
37
|
name: "W3CCredentialStatus",
|
|
29
38
|
reason: {
|
|
30
|
-
message: verificationResult.error
|
|
39
|
+
message: verificationResult.map((r) => r.error).join(", ")
|
|
31
40
|
},
|
|
41
|
+
data: verificationResult,
|
|
32
42
|
status: "ERROR"
|
|
33
43
|
};
|
|
34
|
-
} else if (verificationResult.status ===
|
|
44
|
+
} else if (verificationResult.every((r) => r.status === false)) {
|
|
35
45
|
return {
|
|
36
46
|
type: "DOCUMENT_STATUS",
|
|
37
47
|
name: "W3CCredentialStatus",
|
|
38
|
-
data:
|
|
39
|
-
status: "
|
|
48
|
+
data: verificationResult,
|
|
49
|
+
status: "VALID"
|
|
40
50
|
};
|
|
41
51
|
} else {
|
|
42
52
|
return {
|
|
43
53
|
type: "DOCUMENT_STATUS",
|
|
44
54
|
name: "W3CCredentialStatus",
|
|
45
|
-
data:
|
|
46
|
-
status: "
|
|
55
|
+
data: verificationResult,
|
|
56
|
+
status: "INVALID"
|
|
47
57
|
};
|
|
48
58
|
}
|
|
49
59
|
}, "verify")
|
package/dist/verify/fragments/document-status/transferableRecords/transferableRecordVerifier.js
CHANGED
|
@@ -30,45 +30,46 @@ const TRANSFERABLE_RECORDS_TYPE = "TransferableRecords";
|
|
|
30
30
|
const type = "DOCUMENT_STATUS";
|
|
31
31
|
const name = TRANSFERABLE_RECORDS_TYPE;
|
|
32
32
|
const verify = /* @__PURE__ */ __name(async (document, options) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (w3cVC__namespace.isSignedDocument(document)) {
|
|
36
|
-
signedDocument = document;
|
|
37
|
-
tokenId = "0x" + signedDocument?.credentialStatus?.tokenId;
|
|
38
|
-
}
|
|
39
|
-
const credentialStatus = signedDocument?.credentialStatus;
|
|
40
|
-
if (!credentialStatus?.tokenRegistry) {
|
|
41
|
-
throw new ttVerify.CodedError(
|
|
42
|
-
"Document's credentialStatus does not have tokenRegistry",
|
|
43
|
-
ttVerify.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT,
|
|
44
|
-
ttVerify.OpenAttestationEthereumTokenRegistryStatusCode[ttVerify.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
if (!credentialStatus?.tokenNetwork || !credentialStatus?.tokenNetwork?.chainId) {
|
|
48
|
-
throw new ttVerify.CodedError(
|
|
49
|
-
"Document's credentialStatus does not have tokenNetwork.chainId",
|
|
50
|
-
ttVerify.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT,
|
|
51
|
-
ttVerify.OpenAttestationEthereumTokenRegistryStatusCode[ttVerify.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]
|
|
52
|
-
);
|
|
53
|
-
}
|
|
33
|
+
const signedDocument = document;
|
|
34
|
+
const credentialStatuses = Array.isArray(signedDocument?.credentialStatus) ? signedDocument?.credentialStatus : [signedDocument?.credentialStatus];
|
|
54
35
|
const { provider } = options;
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
36
|
+
const verificationResult = await Promise.all(
|
|
37
|
+
credentialStatuses.map(async (credentialStatus) => {
|
|
38
|
+
const tokenId = "0x" + credentialStatus.tokenId;
|
|
39
|
+
if (!credentialStatus?.tokenRegistry) {
|
|
40
|
+
throw new ttVerify.CodedError(
|
|
41
|
+
"Document's credentialStatus does not have tokenRegistry",
|
|
42
|
+
ttVerify.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT,
|
|
43
|
+
ttVerify.OpenAttestationEthereumTokenRegistryStatusCode[ttVerify.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (!credentialStatus?.tokenNetwork || !credentialStatus?.tokenNetwork?.chainId) {
|
|
47
|
+
throw new ttVerify.CodedError(
|
|
48
|
+
"Document's credentialStatus does not have tokenNetwork.chainId",
|
|
49
|
+
ttVerify.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT,
|
|
50
|
+
ttVerify.OpenAttestationEthereumTokenRegistryStatusCode[ttVerify.OpenAttestationEthereumTokenRegistryStatusCode.UNRECOGNIZED_DOCUMENT]
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
const mintStatus = await utils.isTokenMintedOnRegistry({
|
|
54
|
+
tokenRegistryAddress: credentialStatus?.tokenRegistry,
|
|
55
|
+
tokenId,
|
|
56
|
+
provider
|
|
57
|
+
});
|
|
58
|
+
return mintStatus;
|
|
59
|
+
})
|
|
60
|
+
);
|
|
60
61
|
const result = {
|
|
61
62
|
name,
|
|
62
63
|
type,
|
|
63
64
|
status: "INVALID",
|
|
64
65
|
data: {
|
|
65
|
-
tokenRegistry:
|
|
66
|
+
tokenRegistry: credentialStatuses?.[0]?.tokenRegistry
|
|
66
67
|
}
|
|
67
68
|
};
|
|
68
|
-
if (ttVerify.ValidTokenRegistryStatus.guard
|
|
69
|
+
if (verificationResult.every(ttVerify.ValidTokenRegistryStatus.guard)) {
|
|
69
70
|
result.status = "VALID";
|
|
70
71
|
} else {
|
|
71
|
-
result.reason =
|
|
72
|
+
result.reason = verificationResult?.[0]?.reason;
|
|
72
73
|
}
|
|
73
74
|
return result;
|
|
74
75
|
}, "verify");
|
|
@@ -85,7 +86,9 @@ const skip = /* @__PURE__ */ __name(async () => {
|
|
|
85
86
|
};
|
|
86
87
|
}, "skip");
|
|
87
88
|
const test = /* @__PURE__ */ __name((document) => {
|
|
88
|
-
|
|
89
|
+
const doc = document;
|
|
90
|
+
const credentialStatuses = Array.isArray(doc?.credentialStatus) ? doc?.credentialStatus : [doc?.credentialStatus];
|
|
91
|
+
if (w3cVC__namespace.isSignedDocument(document) && credentialStatuses.every((cs) => cs?.type === TRANSFERABLE_RECORDS_TYPE)) {
|
|
89
92
|
return true;
|
|
90
93
|
}
|
|
91
94
|
return false;
|
|
@@ -18,13 +18,5 @@ type TransferableRecordsErrorFragment = Omit<ErrorVerificationFragment<never>, '
|
|
|
18
18
|
};
|
|
19
19
|
type TransferableRecordsVerificationFragment = TransferableRecordsResultFragment | TransferableRecordsErrorFragment;
|
|
20
20
|
type VerifierType = Verifier<TransferableRecordsVerificationFragment>;
|
|
21
|
-
type TransferableRecordCredentialStatus = {
|
|
22
|
-
type: 'TransferableRecords';
|
|
23
|
-
tokenRegistry: string;
|
|
24
|
-
tokenNetwork: {
|
|
25
|
-
chainId: number;
|
|
26
|
-
name: string;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
21
|
|
|
30
|
-
export type {
|
|
22
|
+
export type { TransferableRecordsErrorFragment, TransferableRecordsErrorReason, TransferableRecordsResultFragment, TransferableRecordsVerificationFragment, VerifierType };
|
|
@@ -18,13 +18,5 @@ type TransferableRecordsErrorFragment = Omit<ErrorVerificationFragment<never>, '
|
|
|
18
18
|
};
|
|
19
19
|
type TransferableRecordsVerificationFragment = TransferableRecordsResultFragment | TransferableRecordsErrorFragment;
|
|
20
20
|
type VerifierType = Verifier<TransferableRecordsVerificationFragment>;
|
|
21
|
-
type TransferableRecordCredentialStatus = {
|
|
22
|
-
type: 'TransferableRecords';
|
|
23
|
-
tokenRegistry: string;
|
|
24
|
-
tokenNetwork: {
|
|
25
|
-
chainId: number;
|
|
26
|
-
name: string;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
21
|
|
|
30
|
-
export type {
|
|
22
|
+
export type { TransferableRecordsErrorFragment, TransferableRecordsErrorReason, TransferableRecordsResultFragment, TransferableRecordsVerificationFragment, VerifierType };
|
|
@@ -19,33 +19,43 @@ const w3cCredentialStatus = {
|
|
|
19
19
|
}, "skip"),
|
|
20
20
|
test: /* @__PURE__ */ __name((document) => {
|
|
21
21
|
const doc = document;
|
|
22
|
-
|
|
22
|
+
const credentialStatuses = Array.isArray(doc?.credentialStatus) ? doc?.credentialStatus : [doc?.credentialStatus];
|
|
23
|
+
const test = /* @__PURE__ */ __name((credentialStatus) => ["BitstringStatusListEntry", "StatusList2021Entry"].includes(credentialStatus?.type), "test");
|
|
24
|
+
if (w3cVc.isSignedDocument(document) && credentialStatuses.every(test)) {
|
|
25
|
+
return true;
|
|
26
|
+
} else {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
23
29
|
}, "test"),
|
|
24
30
|
verify: /* @__PURE__ */ __name(async (document) => {
|
|
25
31
|
const doc = document;
|
|
26
|
-
const
|
|
27
|
-
|
|
32
|
+
const credentialStatuses = Array.isArray(doc.credentialStatus) ? doc.credentialStatus : [doc.credentialStatus];
|
|
33
|
+
const verificationResult = await Promise.all(
|
|
34
|
+
credentialStatuses.map((cs) => w3cVc.verifyCredentialStatus(cs, cs?.type))
|
|
35
|
+
);
|
|
36
|
+
if (verificationResult.some((r) => r.error)) {
|
|
28
37
|
return {
|
|
29
38
|
type: "DOCUMENT_STATUS",
|
|
30
39
|
name: "W3CCredentialStatus",
|
|
31
40
|
reason: {
|
|
32
|
-
message: verificationResult.error
|
|
41
|
+
message: verificationResult.map((r) => r.error).join(", ")
|
|
33
42
|
},
|
|
43
|
+
data: verificationResult,
|
|
34
44
|
status: "ERROR"
|
|
35
45
|
};
|
|
36
|
-
} else if (verificationResult.status ===
|
|
46
|
+
} else if (verificationResult.every((r) => r.status === false)) {
|
|
37
47
|
return {
|
|
38
48
|
type: "DOCUMENT_STATUS",
|
|
39
49
|
name: "W3CCredentialStatus",
|
|
40
|
-
data:
|
|
41
|
-
status: "
|
|
50
|
+
data: verificationResult,
|
|
51
|
+
status: "VALID"
|
|
42
52
|
};
|
|
43
53
|
} else {
|
|
44
54
|
return {
|
|
45
55
|
type: "DOCUMENT_STATUS",
|
|
46
56
|
name: "W3CCredentialStatus",
|
|
47
|
-
data:
|
|
48
|
-
status: "
|
|
57
|
+
data: verificationResult,
|
|
58
|
+
status: "INVALID"
|
|
49
59
|
};
|
|
50
60
|
}
|
|
51
61
|
}, "verify")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trustvc/trustvc",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "TrustVC library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -109,16 +109,16 @@
|
|
|
109
109
|
}
|
|
110
110
|
},
|
|
111
111
|
"dependencies": {
|
|
112
|
-
"@tradetrust-tt/dnsprove": "^2.
|
|
112
|
+
"@tradetrust-tt/dnsprove": "^2.16.0",
|
|
113
113
|
"@tradetrust-tt/token-registry-v4": "npm:@tradetrust-tt/token-registry@^4.15.0",
|
|
114
114
|
"@tradetrust-tt/token-registry-v5": "npm:@tradetrust-tt/token-registry@^5.1.0",
|
|
115
115
|
"@tradetrust-tt/tradetrust": "^6.10.0",
|
|
116
116
|
"@tradetrust-tt/tradetrust-utils": "^2.1.1",
|
|
117
|
-
"@tradetrust-tt/tt-verify": "^9.
|
|
118
|
-
"@trustvc/w3c-context": "^1.
|
|
119
|
-
"@trustvc/w3c-credential-status": "^1.
|
|
120
|
-
"@trustvc/w3c-issuer": "^1.
|
|
121
|
-
"@trustvc/w3c-vc": "^1.
|
|
117
|
+
"@tradetrust-tt/tt-verify": "^9.3.0",
|
|
118
|
+
"@trustvc/w3c-context": "^1.2.1",
|
|
119
|
+
"@trustvc/w3c-credential-status": "^1.2.1",
|
|
120
|
+
"@trustvc/w3c-issuer": "^1.2.1",
|
|
121
|
+
"@trustvc/w3c-vc": "^1.2.3",
|
|
122
122
|
"did-resolver": "^4.1.0",
|
|
123
123
|
"ethers": "^5.7.2",
|
|
124
124
|
"js-sha3": "^0.9.3",
|