@trustvc/trustvc 0.0.0 → 1.0.0-alpha.2
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/LICENSE +201 -0
- package/dist/__tests__/fixtures/fixtures.d.mts +436 -0
- package/dist/__tests__/fixtures/fixtures.d.ts +436 -0
- package/dist/__tests__/fixtures/fixtures.js +715 -0
- package/dist/core/decrypt.d.mts +3 -0
- package/dist/core/decrypt.d.ts +3 -0
- package/dist/core/decrypt.js +23 -0
- package/dist/core/encrypt.d.mts +3 -0
- package/dist/core/encrypt.d.ts +3 -0
- package/dist/core/encrypt.js +23 -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/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 +34 -0
- package/dist/esm/__tests__/fixtures/fixtures.js +701 -0
- package/dist/esm/core/decrypt.js +21 -0
- package/dist/esm/core/encrypt.js +21 -0
- package/dist/esm/core/fragments/document-integrity/w3cSignatureIntegrity.js +46 -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 +32 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/open-attestation/index.js +4 -0
- package/dist/esm/open-attestation/sign.js +10 -0
- package/dist/esm/open-attestation/types.js +1 -0
- package/dist/esm/open-attestation/verify.js +13 -0
- package/dist/esm/open-attestation/wrap.js +10 -0
- package/dist/esm/utils/stringUtils.js +21 -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 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +24 -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 +33 -0
- package/dist/open-attestation/sign.d.mts +7 -0
- package/dist/open-attestation/sign.d.ts +7 -0
- package/dist/open-attestation/sign.js +12 -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/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 +5 -0
- package/dist/open-attestation/wrap.d.ts +5 -0
- package/dist/open-attestation/wrap.js +12 -0
- package/dist/utils/stringUtils.d.mts +5 -0
- package/dist/utils/stringUtils.d.ts +5 -0
- package/dist/utils/stringUtils.js +25 -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 +16 -2
- package/dist/.coverage/.tmp/coverage-0.json +0 -1
- package/dist/esm/.coverage/.tmp/coverage-0.json +0 -1
- package/dist/esm/node_modules/.vitest/vitest/results.json +0 -1
- package/dist/esm/types.js +0 -1
- package/dist/node_modules/.vitest/vitest/results.json +0 -1
- package/dist/types.d.mts +0 -2
- package/dist/types.d.ts +0 -2
- package/dist/types.js +0 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stringUtils = require('src/utils/stringUtils');
|
|
4
|
+
var tsChacha20 = require('ts-chacha20');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
function decrypt(encryptedMessage, key, nonce) {
|
|
9
|
+
if (key.length === 0) {
|
|
10
|
+
throw new Error("Key length must not be 0");
|
|
11
|
+
}
|
|
12
|
+
key = stringUtils.generate32ByteKey(key ?? "");
|
|
13
|
+
nonce = stringUtils.generate12ByteNonce(nonce ?? "");
|
|
14
|
+
const keyBuffer = stringUtils.stringToUint8Array(key);
|
|
15
|
+
const nonceBuffer = stringUtils.stringToUint8Array(nonce);
|
|
16
|
+
const chacha20 = new tsChacha20.Chacha20(keyBuffer, nonceBuffer);
|
|
17
|
+
const encryptedBuffer = Buffer.from(encryptedMessage, "hex");
|
|
18
|
+
const decrypted = chacha20.decrypt(encryptedBuffer);
|
|
19
|
+
return Buffer.from(decrypted).toString("utf-8");
|
|
20
|
+
}
|
|
21
|
+
__name(decrypt, "decrypt");
|
|
22
|
+
|
|
23
|
+
exports.decrypt = decrypt;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stringUtils = require('src/utils/stringUtils');
|
|
4
|
+
var tsChacha20 = require('ts-chacha20');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
function encrypt(message, key, nonce) {
|
|
9
|
+
if (key.length === 0) {
|
|
10
|
+
throw new Error("Key length must not be 0");
|
|
11
|
+
}
|
|
12
|
+
key = stringUtils.generate32ByteKey(key);
|
|
13
|
+
nonce = stringUtils.generate12ByteNonce(nonce ?? "");
|
|
14
|
+
const keyBuffer = stringUtils.stringToUint8Array(key);
|
|
15
|
+
const nonceBuffer = stringUtils.stringToUint8Array(nonce);
|
|
16
|
+
const chacha20 = new tsChacha20.Chacha20(keyBuffer, nonceBuffer);
|
|
17
|
+
const messageBuffer = Buffer.from(message, "utf-8");
|
|
18
|
+
const encrypted = chacha20.encrypt(messageBuffer);
|
|
19
|
+
return Buffer.from(encrypted).toString("hex");
|
|
20
|
+
}
|
|
21
|
+
__name(encrypt, "encrypt");
|
|
22
|
+
|
|
23
|
+
exports.encrypt = encrypt;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __ = require('../../..');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
const w3cSignatureIntegrity = {
|
|
8
|
+
skip: /* @__PURE__ */ __name(async () => {
|
|
9
|
+
return {
|
|
10
|
+
type: "DOCUMENT_INTEGRITY",
|
|
11
|
+
name: "W3CSignatureIntegrity",
|
|
12
|
+
reason: {
|
|
13
|
+
code: 0,
|
|
14
|
+
codeString: "SKIPPED",
|
|
15
|
+
message: `Document either has no proof or proof.type is not 'BbsBlsSignature2020'.`
|
|
16
|
+
},
|
|
17
|
+
status: "SKIPPED"
|
|
18
|
+
};
|
|
19
|
+
}, "skip"),
|
|
20
|
+
test: /* @__PURE__ */ __name((document) => {
|
|
21
|
+
const doc = document;
|
|
22
|
+
return doc.proof?.type === "BbsBlsSignature2020";
|
|
23
|
+
}, "test"),
|
|
24
|
+
verify: /* @__PURE__ */ __name(async (document) => {
|
|
25
|
+
const doc = document;
|
|
26
|
+
const verificationResult = await __.verifyW3CSignature(doc);
|
|
27
|
+
if (verificationResult.verified) {
|
|
28
|
+
return {
|
|
29
|
+
type: "DOCUMENT_INTEGRITY",
|
|
30
|
+
name: "W3CSignatureIntegrity",
|
|
31
|
+
data: true,
|
|
32
|
+
status: "VALID"
|
|
33
|
+
};
|
|
34
|
+
} else {
|
|
35
|
+
return {
|
|
36
|
+
type: "DOCUMENT_INTEGRITY",
|
|
37
|
+
name: "W3CSignatureIntegrity",
|
|
38
|
+
data: false,
|
|
39
|
+
reason: {
|
|
40
|
+
message: verificationResult.error
|
|
41
|
+
},
|
|
42
|
+
status: "INVALID"
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}, "verify")
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.w3cSignatureIntegrity = w3cSignatureIntegrity;
|
|
@@ -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 '@govtechsg/oa-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 '@govtechsg/oa-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,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var oaVerify = require('@govtechsg/oa-verify');
|
|
4
|
+
var ethers = require('ethers');
|
|
5
|
+
var w3cSignatureIntegrity = require('./fragments/document-integrity/w3cSignatureIntegrity');
|
|
6
|
+
var w3cCredentialStatus = require('./fragments/document-status/w3cCredentialStatus');
|
|
7
|
+
var w3cIssuerIdentity = require('./fragments/issuer-identity/w3cIssuerIdentity');
|
|
8
|
+
var openAttestation = require('@govtechsg/open-attestation');
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
const verifyDocument = /* @__PURE__ */ __name(async (document, rpcProviderUrl) => {
|
|
13
|
+
if (openAttestation.utils.isWrappedV2Document(document) || openAttestation.utils.isWrappedV3Document(document) || openAttestation.utils.isWrappedV4Document(document)) {
|
|
14
|
+
const verify = oaVerify.verificationBuilder(
|
|
15
|
+
[...oaVerify.openAttestationVerifiers, oaVerify.openAttestationDidIdentityProof],
|
|
16
|
+
{
|
|
17
|
+
provider: new ethers.ethers.providers.JsonRpcProvider(rpcProviderUrl)
|
|
18
|
+
// Use user-provided provider URL
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
return verify(document);
|
|
22
|
+
} else {
|
|
23
|
+
const verify = oaVerify.verificationBuilder(
|
|
24
|
+
[w3cSignatureIntegrity.w3cSignatureIntegrity, w3cCredentialStatus.w3cCredentialStatus, w3cIssuerIdentity.w3cIssuerIdentity],
|
|
25
|
+
{
|
|
26
|
+
provider: new ethers.ethers.providers.JsonRpcProvider(rpcProviderUrl)
|
|
27
|
+
// Use user-provided provider URL
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
return verify(document);
|
|
31
|
+
}
|
|
32
|
+
}, "verifyDocument");
|
|
33
|
+
|
|
34
|
+
exports.verifyDocument = verifyDocument;
|