@trustvc/trustvc 1.0.0-alpha.1 → 1.0.0-alpha.10
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/README.md +138 -0
- package/dist/config.d.mts +3 -0
- package/dist/config.d.ts +3 -0
- package/dist/config.js +5 -0
- package/dist/core/decrypt.d.mts +3 -0
- package/dist/core/decrypt.d.ts +3 -0
- package/dist/core/decrypt.js +22 -0
- package/dist/core/encrypt.d.mts +3 -0
- package/dist/core/encrypt.d.ts +3 -0
- package/dist/core/encrypt.js +22 -0
- package/dist/core/fragments/document-integrity/w3cSignatureIntegrity.d.mts +5 -0
- package/dist/core/fragments/document-integrity/w3cSignatureIntegrity.d.ts +5 -0
- package/dist/core/fragments/document-integrity/w3cSignatureIntegrity.js +48 -0
- package/dist/core/fragments/document-status/transferableRecords/transferableRecordVerifier.d.mts +7 -0
- package/dist/core/fragments/document-status/transferableRecords/transferableRecordVerifier.d.ts +7 -0
- package/dist/core/fragments/document-status/transferableRecords/transferableRecordVerifier.js +128 -0
- package/dist/core/fragments/document-status/transferableRecords/transferableRecordVerifier.types.d.mts +30 -0
- package/dist/core/fragments/document-status/transferableRecords/transferableRecordVerifier.types.d.ts +30 -0
- package/dist/core/fragments/document-status/transferableRecords/transferableRecordVerifier.types.js +2 -0
- package/dist/core/fragments/document-status/transferableRecords/utils.d.mts +18 -0
- package/dist/core/fragments/document-status/transferableRecords/utils.d.ts +18 -0
- package/dist/core/fragments/document-status/transferableRecords/utils.js +75 -0
- package/dist/core/fragments/document-status/w3cCredentialStatus.d.mts +5 -0
- package/dist/core/fragments/document-status/w3cCredentialStatus.d.ts +5 -0
- package/dist/core/fragments/document-status/w3cCredentialStatus.js +54 -0
- package/dist/core/fragments/issuer-identity/w3cIssuerIdentity.d.mts +5 -0
- package/dist/core/fragments/issuer-identity/w3cIssuerIdentity.d.ts +5 -0
- package/dist/core/fragments/issuer-identity/w3cIssuerIdentity.js +74 -0
- package/dist/core/index.d.mts +5 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +26 -0
- package/dist/core/verify.d.mts +6 -0
- package/dist/core/verify.d.ts +6 -0
- package/dist/core/verify.js +40 -0
- package/dist/esm/config.js +3 -0
- package/dist/esm/core/decrypt.js +20 -0
- package/dist/esm/core/encrypt.js +20 -0
- package/dist/esm/core/fragments/document-integrity/w3cSignatureIntegrity.js +46 -0
- package/dist/esm/core/fragments/document-status/transferableRecords/transferableRecordVerifier.js +105 -0
- package/dist/esm/core/fragments/document-status/transferableRecords/transferableRecordVerifier.types.js +1 -0
- package/dist/esm/core/fragments/document-status/transferableRecords/utils.js +72 -0
- package/dist/esm/core/fragments/document-status/w3cCredentialStatus.js +52 -0
- package/dist/esm/core/fragments/issuer-identity/w3cIssuerIdentity.js +72 -0
- package/dist/esm/core/index.js +3 -0
- package/dist/esm/core/verify.js +38 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/open-attestation/index.js +5 -0
- package/dist/esm/open-attestation/sign.js +15 -0
- package/dist/esm/open-attestation/types.js +1 -0
- package/dist/esm/open-attestation/utils.js +1 -0
- package/dist/esm/open-attestation/verify.js +13 -0
- package/dist/esm/open-attestation/wrap.js +33 -0
- package/dist/esm/utils/stringUtils.js +20 -0
- package/dist/esm/w3c/index.js +3 -0
- package/dist/esm/w3c/sign.js +9 -0
- package/dist/esm/w3c/types.js +2 -0
- package/dist/esm/w3c/verify.js +9 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +26 -0
- package/dist/open-attestation/index.d.mts +6 -0
- package/dist/open-attestation/index.d.ts +6 -0
- package/dist/open-attestation/index.js +40 -0
- package/dist/open-attestation/sign.d.mts +8 -0
- package/dist/open-attestation/sign.d.ts +8 -0
- package/dist/open-attestation/sign.js +17 -0
- package/dist/open-attestation/types.d.mts +8 -0
- package/dist/open-attestation/types.d.ts +8 -0
- package/dist/open-attestation/types.js +18 -0
- package/dist/open-attestation/utils.d.mts +3 -0
- package/dist/open-attestation/utils.d.ts +3 -0
- package/dist/open-attestation/utils.js +10 -0
- package/dist/open-attestation/verify.d.mts +5 -0
- package/dist/open-attestation/verify.d.ts +5 -0
- package/dist/open-attestation/verify.js +15 -0
- package/dist/open-attestation/wrap.d.mts +9 -0
- package/dist/open-attestation/wrap.d.ts +9 -0
- package/dist/open-attestation/wrap.js +45 -0
- package/dist/utils/stringUtils.d.mts +5 -0
- package/dist/utils/stringUtils.d.ts +5 -0
- package/dist/utils/stringUtils.js +24 -0
- package/dist/w3c/index.d.mts +4 -0
- package/dist/w3c/index.d.ts +4 -0
- package/dist/w3c/index.js +26 -0
- package/dist/w3c/sign.d.mts +6 -0
- package/dist/w3c/sign.d.ts +6 -0
- package/dist/w3c/sign.js +11 -0
- package/dist/w3c/types.d.mts +2 -0
- package/dist/w3c/types.d.ts +2 -0
- package/dist/w3c/types.js +27 -0
- package/dist/w3c/verify.d.mts +5 -0
- package/dist/w3c/verify.d.ts +5 -0
- package/dist/w3c/verify.js +11 -0
- package/package.json +13 -7
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var w3cVc = require('@trustvc/w3c-vc');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
const w3cCredentialStatus = {
|
|
8
|
+
skip: /* @__PURE__ */ __name(async () => {
|
|
9
|
+
return {
|
|
10
|
+
type: "DOCUMENT_STATUS",
|
|
11
|
+
name: "W3CCredentialStatus",
|
|
12
|
+
reason: {
|
|
13
|
+
code: 0,
|
|
14
|
+
codeString: "SKIPPED",
|
|
15
|
+
message: `Document does not have a valid credentialStatus or type.`
|
|
16
|
+
},
|
|
17
|
+
status: "SKIPPED"
|
|
18
|
+
};
|
|
19
|
+
}, "skip"),
|
|
20
|
+
test: /* @__PURE__ */ __name((document) => {
|
|
21
|
+
const doc = document;
|
|
22
|
+
return doc.credentialStatus?.type === "StatusList2021Entry";
|
|
23
|
+
}, "test"),
|
|
24
|
+
verify: /* @__PURE__ */ __name(async (document) => {
|
|
25
|
+
const doc = document;
|
|
26
|
+
const verificationResult = await w3cVc.verifyCredentialStatus(doc.credentialStatus);
|
|
27
|
+
if (verificationResult.error) {
|
|
28
|
+
return {
|
|
29
|
+
type: "DOCUMENT_STATUS",
|
|
30
|
+
name: "W3CCredentialStatus",
|
|
31
|
+
reason: {
|
|
32
|
+
message: verificationResult.error
|
|
33
|
+
},
|
|
34
|
+
status: "ERROR"
|
|
35
|
+
};
|
|
36
|
+
} else if (verificationResult.status === true) {
|
|
37
|
+
return {
|
|
38
|
+
type: "DOCUMENT_STATUS",
|
|
39
|
+
name: "W3CCredentialStatus",
|
|
40
|
+
data: false,
|
|
41
|
+
status: "INVALID"
|
|
42
|
+
};
|
|
43
|
+
} else {
|
|
44
|
+
return {
|
|
45
|
+
type: "DOCUMENT_STATUS",
|
|
46
|
+
name: "W3CCredentialStatus",
|
|
47
|
+
data: true,
|
|
48
|
+
status: "VALID"
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}, "verify")
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
exports.w3cCredentialStatus = w3cCredentialStatus;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var didResolver = require('did-resolver');
|
|
4
|
+
var webDidResolver = require('web-did-resolver');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
const checkDidWebResolve = /* @__PURE__ */ __name(async (did) => {
|
|
9
|
+
try {
|
|
10
|
+
const resolver = new didResolver.Resolver({
|
|
11
|
+
...webDidResolver.getResolver()
|
|
12
|
+
});
|
|
13
|
+
const didDocument = await resolver.resolve(did);
|
|
14
|
+
if (!didDocument || !didDocument.didDocument) {
|
|
15
|
+
throw new Error(`Failed to resolve DID: ${did}`);
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
} catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}, "checkDidWebResolve");
|
|
22
|
+
const w3cIssuerIdentity = {
|
|
23
|
+
skip: /* @__PURE__ */ __name(async () => {
|
|
24
|
+
return {
|
|
25
|
+
type: "ISSUER_IDENTITY",
|
|
26
|
+
name: "W3CIssuerIdentity",
|
|
27
|
+
reason: {
|
|
28
|
+
code: 0,
|
|
29
|
+
codeString: "SKIPPED",
|
|
30
|
+
message: `Document has no issuer field.`
|
|
31
|
+
},
|
|
32
|
+
status: "SKIPPED"
|
|
33
|
+
};
|
|
34
|
+
}, "skip"),
|
|
35
|
+
test: /* @__PURE__ */ __name((document) => {
|
|
36
|
+
const doc = document;
|
|
37
|
+
return Boolean(doc.issuer);
|
|
38
|
+
}, "test"),
|
|
39
|
+
verify: /* @__PURE__ */ __name(async (document) => {
|
|
40
|
+
const doc = document;
|
|
41
|
+
if (doc.proof?.verificationMethod?.split("#")[0] !== doc.issuer) {
|
|
42
|
+
return {
|
|
43
|
+
type: "ISSUER_IDENTITY",
|
|
44
|
+
name: "W3CIssuerIdentity",
|
|
45
|
+
data: false,
|
|
46
|
+
reason: {
|
|
47
|
+
message: `Issuer and verification method do not match.`
|
|
48
|
+
},
|
|
49
|
+
status: "INVALID"
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const resolutionResult = await checkDidWebResolve(doc.issuer);
|
|
53
|
+
if (resolutionResult) {
|
|
54
|
+
return {
|
|
55
|
+
type: "ISSUER_IDENTITY",
|
|
56
|
+
name: "W3CIssuerIdentity",
|
|
57
|
+
data: true,
|
|
58
|
+
status: "VALID"
|
|
59
|
+
};
|
|
60
|
+
} else {
|
|
61
|
+
return {
|
|
62
|
+
type: "ISSUER_IDENTITY",
|
|
63
|
+
name: "W3CIssuerIdentity",
|
|
64
|
+
data: false,
|
|
65
|
+
reason: {
|
|
66
|
+
message: `The DID cannot be resolved.`
|
|
67
|
+
},
|
|
68
|
+
status: "INVALID"
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}, "verify")
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
exports.w3cIssuerIdentity = w3cIssuerIdentity;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var verify = require('./verify');
|
|
4
|
+
var encrypt = require('./encrypt');
|
|
5
|
+
var decrypt = require('./decrypt');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.keys(verify).forEach(function (k) {
|
|
10
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () { return verify[k]; }
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
Object.keys(encrypt).forEach(function (k) {
|
|
16
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return encrypt[k]; }
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
Object.keys(decrypt).forEach(function (k) {
|
|
22
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return decrypt[k]; }
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DocumentsToVerify, VerificationFragment } from '@tradetrust-tt/tt-verify';
|
|
2
|
+
import { SignedVerifiableCredential } from '@trustvc/w3c-vc';
|
|
3
|
+
|
|
4
|
+
declare const verifyDocument: (document: DocumentsToVerify | SignedVerifiableCredential, rpcProviderUrl: string) => Promise<VerificationFragment[]>;
|
|
5
|
+
|
|
6
|
+
export { verifyDocument };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DocumentsToVerify, VerificationFragment } from '@tradetrust-tt/tt-verify';
|
|
2
|
+
import { SignedVerifiableCredential } from '@trustvc/w3c-vc';
|
|
3
|
+
|
|
4
|
+
declare const verifyDocument: (document: DocumentsToVerify | SignedVerifiableCredential, rpcProviderUrl: string) => Promise<VerificationFragment[]>;
|
|
5
|
+
|
|
6
|
+
export { verifyDocument };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tradetrust = require('@tradetrust-tt/tradetrust');
|
|
4
|
+
var ttVerify = require('@tradetrust-tt/tt-verify');
|
|
5
|
+
var ethers = require('ethers');
|
|
6
|
+
var w3cSignatureIntegrity = require('./fragments/document-integrity/w3cSignatureIntegrity');
|
|
7
|
+
var transferableRecordVerifier = require('./fragments/document-status/transferableRecords/transferableRecordVerifier');
|
|
8
|
+
var w3cCredentialStatus = require('./fragments/document-status/w3cCredentialStatus');
|
|
9
|
+
var w3cIssuerIdentity = require('./fragments/issuer-identity/w3cIssuerIdentity');
|
|
10
|
+
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
const verifyDocument = /* @__PURE__ */ __name(async (document, rpcProviderUrl) => {
|
|
14
|
+
if (tradetrust.utils.isWrappedV2Document(document) || tradetrust.utils.isWrappedV3Document(document)) {
|
|
15
|
+
const verify = ttVerify.verificationBuilder(
|
|
16
|
+
[...ttVerify.openAttestationVerifiers, ttVerify.openAttestationDidIdentityProof],
|
|
17
|
+
{
|
|
18
|
+
provider: new ethers.ethers.providers.JsonRpcProvider(rpcProviderUrl)
|
|
19
|
+
// Use user-provided provider URL
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
return verify(document);
|
|
23
|
+
} else {
|
|
24
|
+
const verify = ttVerify.verificationBuilder(
|
|
25
|
+
[
|
|
26
|
+
w3cSignatureIntegrity.w3cSignatureIntegrity,
|
|
27
|
+
w3cCredentialStatus.w3cCredentialStatus,
|
|
28
|
+
w3cIssuerIdentity.w3cIssuerIdentity,
|
|
29
|
+
transferableRecordVerifier.credentialStatusTransferableRecordVerifier
|
|
30
|
+
],
|
|
31
|
+
{
|
|
32
|
+
provider: new ethers.ethers.providers.JsonRpcProvider(rpcProviderUrl)
|
|
33
|
+
// Use user-provided provider URL
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
return verify(document);
|
|
37
|
+
}
|
|
38
|
+
}, "verifyDocument");
|
|
39
|
+
|
|
40
|
+
exports.verifyDocument = verifyDocument;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DEFAULT_KEY } from '../config';
|
|
2
|
+
import { generate32ByteKey, generate12ByteNonce, stringToUint8Array } from '../utils/stringUtils';
|
|
3
|
+
import { Chacha20 } from 'ts-chacha20';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
function decrypt(encryptedMessage, key, nonce) {
|
|
8
|
+
key = key.length > 0 ? key : DEFAULT_KEY;
|
|
9
|
+
key = generate32ByteKey(key);
|
|
10
|
+
nonce = generate12ByteNonce(nonce ?? "");
|
|
11
|
+
const keyBuffer = stringToUint8Array(key);
|
|
12
|
+
const nonceBuffer = stringToUint8Array(nonce);
|
|
13
|
+
const chacha20 = new Chacha20(keyBuffer, nonceBuffer);
|
|
14
|
+
const encryptedBuffer = new Uint8Array(Buffer.from(encryptedMessage, "hex"));
|
|
15
|
+
const decrypted = chacha20.decrypt(encryptedBuffer);
|
|
16
|
+
return Buffer.from(decrypted).toString("utf-8");
|
|
17
|
+
}
|
|
18
|
+
__name(decrypt, "decrypt");
|
|
19
|
+
|
|
20
|
+
export { decrypt };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DEFAULT_KEY } from '../config';
|
|
2
|
+
import { generate32ByteKey, generate12ByteNonce, stringToUint8Array } from '../utils/stringUtils';
|
|
3
|
+
import { Chacha20 } from 'ts-chacha20';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
function encrypt(message, key, nonce) {
|
|
8
|
+
key = key.length > 0 ? key : DEFAULT_KEY;
|
|
9
|
+
key = generate32ByteKey(key);
|
|
10
|
+
nonce = generate12ByteNonce(nonce ?? "");
|
|
11
|
+
const keyBuffer = stringToUint8Array(key);
|
|
12
|
+
const nonceBuffer = stringToUint8Array(nonce);
|
|
13
|
+
const chacha20 = new Chacha20(keyBuffer, nonceBuffer);
|
|
14
|
+
const messageBuffer = stringToUint8Array(message);
|
|
15
|
+
const encrypted = chacha20.encrypt(messageBuffer);
|
|
16
|
+
return Buffer.from(encrypted).toString("hex");
|
|
17
|
+
}
|
|
18
|
+
__name(encrypt, "encrypt");
|
|
19
|
+
|
|
20
|
+
export { encrypt };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { verifyW3CSignature } from '../../..';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
const w3cSignatureIntegrity = {
|
|
6
|
+
skip: /* @__PURE__ */ __name(async () => {
|
|
7
|
+
return {
|
|
8
|
+
type: "DOCUMENT_INTEGRITY",
|
|
9
|
+
name: "W3CSignatureIntegrity",
|
|
10
|
+
reason: {
|
|
11
|
+
code: 0,
|
|
12
|
+
codeString: "SKIPPED",
|
|
13
|
+
message: `Document either has no proof or proof.type is not 'BbsBlsSignature2020'.`
|
|
14
|
+
},
|
|
15
|
+
status: "SKIPPED"
|
|
16
|
+
};
|
|
17
|
+
}, "skip"),
|
|
18
|
+
test: /* @__PURE__ */ __name((document) => {
|
|
19
|
+
const doc = document;
|
|
20
|
+
return doc.proof?.type === "BbsBlsSignature2020";
|
|
21
|
+
}, "test"),
|
|
22
|
+
verify: /* @__PURE__ */ __name(async (document) => {
|
|
23
|
+
const doc = document;
|
|
24
|
+
const verificationResult = await verifyW3CSignature(doc);
|
|
25
|
+
if (verificationResult.verified) {
|
|
26
|
+
return {
|
|
27
|
+
type: "DOCUMENT_INTEGRITY",
|
|
28
|
+
name: "W3CSignatureIntegrity",
|
|
29
|
+
data: true,
|
|
30
|
+
status: "VALID"
|
|
31
|
+
};
|
|
32
|
+
} else {
|
|
33
|
+
return {
|
|
34
|
+
type: "DOCUMENT_INTEGRITY",
|
|
35
|
+
name: "W3CSignatureIntegrity",
|
|
36
|
+
data: false,
|
|
37
|
+
reason: {
|
|
38
|
+
message: verificationResult.error
|
|
39
|
+
},
|
|
40
|
+
status: "INVALID"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}, "verify")
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { w3cSignatureIntegrity };
|
package/dist/esm/core/fragments/document-status/transferableRecords/transferableRecordVerifier.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { OpenAttestationEthereumTokenRegistryStatusCode, CodedError, ValidTokenRegistryStatus } from '@tradetrust-tt/tt-verify';
|
|
2
|
+
import * as w3cVC from '@trustvc/w3c-vc';
|
|
3
|
+
import { isTokenMintedOnRegistry } from './utils';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
const TRANSFERABLE_RECORDS_TYPE = "TransferableRecords";
|
|
8
|
+
const type = "DOCUMENT_STATUS";
|
|
9
|
+
const name = TRANSFERABLE_RECORDS_TYPE;
|
|
10
|
+
const verify = /* @__PURE__ */ __name(async (document, options) => {
|
|
11
|
+
let signedDocument;
|
|
12
|
+
let tokenId;
|
|
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
|
+
}
|
|
32
|
+
const { provider } = options;
|
|
33
|
+
const mintStatus = await isTokenMintedOnRegistry({
|
|
34
|
+
tokenRegistryAddress: credentialStatus?.tokenRegistry,
|
|
35
|
+
tokenId,
|
|
36
|
+
provider
|
|
37
|
+
});
|
|
38
|
+
const result = {
|
|
39
|
+
name,
|
|
40
|
+
type,
|
|
41
|
+
status: "INVALID",
|
|
42
|
+
data: {
|
|
43
|
+
tokenRegistry: credentialStatus.tokenRegistry
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
if (ValidTokenRegistryStatus.guard(mintStatus)) {
|
|
47
|
+
result.status = "VALID";
|
|
48
|
+
} else {
|
|
49
|
+
result.reason = mintStatus.reason;
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}, "verify");
|
|
53
|
+
const skip = /* @__PURE__ */ __name(async () => {
|
|
54
|
+
return {
|
|
55
|
+
status: "SKIPPED",
|
|
56
|
+
type,
|
|
57
|
+
name,
|
|
58
|
+
reason: {
|
|
59
|
+
code: OpenAttestationEthereumTokenRegistryStatusCode.SKIPPED,
|
|
60
|
+
codeString: OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.SKIPPED],
|
|
61
|
+
message: `Document does not have TransferableRecords status`
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}, "skip");
|
|
65
|
+
const test = /* @__PURE__ */ __name((document) => {
|
|
66
|
+
if (document?.credentialStatus?.type === TRANSFERABLE_RECORDS_TYPE) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}, "test");
|
|
71
|
+
const credentialStatusTransferableRecordVerifier = {
|
|
72
|
+
skip,
|
|
73
|
+
test,
|
|
74
|
+
verify: /* @__PURE__ */ __name(async (...args) => {
|
|
75
|
+
try {
|
|
76
|
+
return await verify(...args);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
if (e instanceof CodedError) {
|
|
79
|
+
const err = {
|
|
80
|
+
name,
|
|
81
|
+
type,
|
|
82
|
+
status: "ERROR",
|
|
83
|
+
reason: {
|
|
84
|
+
code: e.code,
|
|
85
|
+
codeString: e.codeString,
|
|
86
|
+
message: e.message
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return err;
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
name,
|
|
93
|
+
type,
|
|
94
|
+
status: "ERROR",
|
|
95
|
+
reason: {
|
|
96
|
+
code: OpenAttestationEthereumTokenRegistryStatusCode.UNEXPECTED_ERROR,
|
|
97
|
+
codeString: OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.UNEXPECTED_ERROR],
|
|
98
|
+
message: e instanceof Error ? e.message : "An unexpected error occurred"
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}, "verify")
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export { TRANSFERABLE_RECORDS_TYPE, credentialStatusTransferableRecordVerifier };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { CodedError, OpenAttestationEthereumTokenRegistryStatusCode } from '@tradetrust-tt/tt-verify';
|
|
2
|
+
import { TradeTrustToken__factory } from '@tradetrust-tt/token-registry/dist/contracts';
|
|
3
|
+
import { errors, constants } from 'ethers';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
const isNonExistentToken = /* @__PURE__ */ __name((error) => {
|
|
8
|
+
const message = error.message;
|
|
9
|
+
if (!message) {
|
|
10
|
+
return error.data && error.data.slice(0, 10) === "0x7e273289";
|
|
11
|
+
}
|
|
12
|
+
return message.includes("owner query for nonexistent token");
|
|
13
|
+
}, "isNonExistentToken");
|
|
14
|
+
const isMissingTokenRegistry = /* @__PURE__ */ __name((error) => {
|
|
15
|
+
return !error.reason && error.method?.toLowerCase() === "ownerOf(uint256)".toLowerCase() && error.code === errors.CALL_EXCEPTION;
|
|
16
|
+
}, "isMissingTokenRegistry");
|
|
17
|
+
const decodeError = /* @__PURE__ */ __name((error) => {
|
|
18
|
+
const reason = error.reason && Array.isArray(error.reason) ? error.reason[0] : error.reason ?? "";
|
|
19
|
+
switch (true) {
|
|
20
|
+
case isNonExistentToken(error):
|
|
21
|
+
return `Document has not been issued under token registry`;
|
|
22
|
+
case isMissingTokenRegistry(error):
|
|
23
|
+
return `Token registry is not found`;
|
|
24
|
+
case (reason.toLowerCase() === "ENS name not configured".toLowerCase() && error.code === errors.UNSUPPORTED_OPERATION):
|
|
25
|
+
return "ENS name is not configured";
|
|
26
|
+
case (reason.toLowerCase() === "invalid address".toLowerCase() && error.code === errors.INVALID_ARGUMENT):
|
|
27
|
+
return `Invalid token registry address`;
|
|
28
|
+
case error.code === errors.INVALID_ARGUMENT:
|
|
29
|
+
return `Invalid contract arguments`;
|
|
30
|
+
case error.code === errors.SERVER_ERROR:
|
|
31
|
+
case error.code === errors.NETWORK_ERROR:
|
|
32
|
+
throw new CodedError(
|
|
33
|
+
"Unable to connect to the network, please try again later",
|
|
34
|
+
OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR,
|
|
35
|
+
OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.SERVER_ERROR]
|
|
36
|
+
);
|
|
37
|
+
default:
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}, "decodeError");
|
|
41
|
+
const isTokenMintedOnRegistry = /* @__PURE__ */ __name(async ({
|
|
42
|
+
tokenRegistryAddress,
|
|
43
|
+
tokenId,
|
|
44
|
+
provider
|
|
45
|
+
}) => {
|
|
46
|
+
try {
|
|
47
|
+
const tokenRegistryContract = TradeTrustToken__factory.connect(tokenRegistryAddress, provider);
|
|
48
|
+
const minted = await tokenRegistryContract.ownerOf(tokenId).then((owner) => owner !== constants.AddressZero);
|
|
49
|
+
return minted ? { minted, address: tokenRegistryAddress } : {
|
|
50
|
+
minted,
|
|
51
|
+
address: tokenRegistryAddress,
|
|
52
|
+
reason: {
|
|
53
|
+
code: OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED,
|
|
54
|
+
codeString: OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED],
|
|
55
|
+
message: `Document ${tokenId} has not been issued under contract ${tokenRegistryAddress}`
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
} catch (error) {
|
|
59
|
+
return {
|
|
60
|
+
minted: false,
|
|
61
|
+
address: tokenRegistryAddress,
|
|
62
|
+
reason: {
|
|
63
|
+
message: decodeError(error),
|
|
64
|
+
// message: (error as Error).message,
|
|
65
|
+
code: OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED,
|
|
66
|
+
codeString: OpenAttestationEthereumTokenRegistryStatusCode[OpenAttestationEthereumTokenRegistryStatusCode.DOCUMENT_NOT_MINTED]
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}, "isTokenMintedOnRegistry");
|
|
71
|
+
|
|
72
|
+
export { decodeError, isTokenMintedOnRegistry };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { verifyCredentialStatus } from '@trustvc/w3c-vc';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
const w3cCredentialStatus = {
|
|
6
|
+
skip: /* @__PURE__ */ __name(async () => {
|
|
7
|
+
return {
|
|
8
|
+
type: "DOCUMENT_STATUS",
|
|
9
|
+
name: "W3CCredentialStatus",
|
|
10
|
+
reason: {
|
|
11
|
+
code: 0,
|
|
12
|
+
codeString: "SKIPPED",
|
|
13
|
+
message: `Document does not have a valid credentialStatus or type.`
|
|
14
|
+
},
|
|
15
|
+
status: "SKIPPED"
|
|
16
|
+
};
|
|
17
|
+
}, "skip"),
|
|
18
|
+
test: /* @__PURE__ */ __name((document) => {
|
|
19
|
+
const doc = document;
|
|
20
|
+
return doc.credentialStatus?.type === "StatusList2021Entry";
|
|
21
|
+
}, "test"),
|
|
22
|
+
verify: /* @__PURE__ */ __name(async (document) => {
|
|
23
|
+
const doc = document;
|
|
24
|
+
const verificationResult = await verifyCredentialStatus(doc.credentialStatus);
|
|
25
|
+
if (verificationResult.error) {
|
|
26
|
+
return {
|
|
27
|
+
type: "DOCUMENT_STATUS",
|
|
28
|
+
name: "W3CCredentialStatus",
|
|
29
|
+
reason: {
|
|
30
|
+
message: verificationResult.error
|
|
31
|
+
},
|
|
32
|
+
status: "ERROR"
|
|
33
|
+
};
|
|
34
|
+
} else if (verificationResult.status === true) {
|
|
35
|
+
return {
|
|
36
|
+
type: "DOCUMENT_STATUS",
|
|
37
|
+
name: "W3CCredentialStatus",
|
|
38
|
+
data: false,
|
|
39
|
+
status: "INVALID"
|
|
40
|
+
};
|
|
41
|
+
} else {
|
|
42
|
+
return {
|
|
43
|
+
type: "DOCUMENT_STATUS",
|
|
44
|
+
name: "W3CCredentialStatus",
|
|
45
|
+
data: true,
|
|
46
|
+
status: "VALID"
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}, "verify")
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { w3cCredentialStatus };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Resolver } from 'did-resolver';
|
|
2
|
+
import { getResolver } from 'web-did-resolver';
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
const checkDidWebResolve = /* @__PURE__ */ __name(async (did) => {
|
|
7
|
+
try {
|
|
8
|
+
const resolver = new Resolver({
|
|
9
|
+
...getResolver()
|
|
10
|
+
});
|
|
11
|
+
const didDocument = await resolver.resolve(did);
|
|
12
|
+
if (!didDocument || !didDocument.didDocument) {
|
|
13
|
+
throw new Error(`Failed to resolve DID: ${did}`);
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}, "checkDidWebResolve");
|
|
20
|
+
const w3cIssuerIdentity = {
|
|
21
|
+
skip: /* @__PURE__ */ __name(async () => {
|
|
22
|
+
return {
|
|
23
|
+
type: "ISSUER_IDENTITY",
|
|
24
|
+
name: "W3CIssuerIdentity",
|
|
25
|
+
reason: {
|
|
26
|
+
code: 0,
|
|
27
|
+
codeString: "SKIPPED",
|
|
28
|
+
message: `Document has no issuer field.`
|
|
29
|
+
},
|
|
30
|
+
status: "SKIPPED"
|
|
31
|
+
};
|
|
32
|
+
}, "skip"),
|
|
33
|
+
test: /* @__PURE__ */ __name((document) => {
|
|
34
|
+
const doc = document;
|
|
35
|
+
return Boolean(doc.issuer);
|
|
36
|
+
}, "test"),
|
|
37
|
+
verify: /* @__PURE__ */ __name(async (document) => {
|
|
38
|
+
const doc = document;
|
|
39
|
+
if (doc.proof?.verificationMethod?.split("#")[0] !== doc.issuer) {
|
|
40
|
+
return {
|
|
41
|
+
type: "ISSUER_IDENTITY",
|
|
42
|
+
name: "W3CIssuerIdentity",
|
|
43
|
+
data: false,
|
|
44
|
+
reason: {
|
|
45
|
+
message: `Issuer and verification method do not match.`
|
|
46
|
+
},
|
|
47
|
+
status: "INVALID"
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const resolutionResult = await checkDidWebResolve(doc.issuer);
|
|
51
|
+
if (resolutionResult) {
|
|
52
|
+
return {
|
|
53
|
+
type: "ISSUER_IDENTITY",
|
|
54
|
+
name: "W3CIssuerIdentity",
|
|
55
|
+
data: true,
|
|
56
|
+
status: "VALID"
|
|
57
|
+
};
|
|
58
|
+
} else {
|
|
59
|
+
return {
|
|
60
|
+
type: "ISSUER_IDENTITY",
|
|
61
|
+
name: "W3CIssuerIdentity",
|
|
62
|
+
data: false,
|
|
63
|
+
reason: {
|
|
64
|
+
message: `The DID cannot be resolved.`
|
|
65
|
+
},
|
|
66
|
+
status: "INVALID"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}, "verify")
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { w3cIssuerIdentity };
|