@trustvc/trustvc 2.9.0 → 2.10.0
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/cjs/__tests__/fixtures/sample-oa-document.json +61 -0
- package/dist/cjs/document-store/document-store-roles.js +4 -10
- package/dist/cjs/document-store/index.js +5 -0
- package/dist/cjs/document-store/transferOwnership.js +55 -7
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/open-attestation/decrypt.js +34 -0
- package/dist/cjs/open-attestation/encrypt.js +47 -0
- package/dist/cjs/open-attestation/index.js +30 -20
- package/dist/cjs/open-attestation/utils.js +43 -0
- package/dist/esm/__tests__/fixtures/sample-oa-document.json +61 -0
- package/dist/esm/document-store/document-store-roles.js +4 -10
- package/dist/esm/document-store/index.js +1 -0
- package/dist/esm/document-store/transferOwnership.js +55 -7
- package/dist/esm/index.js +1 -1
- package/dist/esm/open-attestation/decrypt.js +28 -0
- package/dist/esm/open-attestation/encrypt.js +41 -0
- package/dist/esm/open-attestation/index.js +2 -0
- package/dist/esm/open-attestation/utils.js +36 -1
- package/dist/types/document-store/index.d.ts +1 -0
- package/dist/types/document-store/transferOwnership.d.ts +4 -4
- package/dist/types/index.d.ts +16 -12
- package/dist/types/open-attestation/decrypt.d.ts +12 -0
- package/dist/types/open-attestation/encrypt.d.ts +13 -0
- package/dist/types/open-attestation/index.d.ts +4 -2
- package/dist/types/open-attestation/types.d.ts +8 -1
- package/dist/types/open-attestation/utils.d.ts +32 -1
- package/package.json +3 -1
|
@@ -19,17 +19,11 @@ const getRoleString = /* @__PURE__ */ __name(async (documentStoreAddress, role,
|
|
|
19
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
20
|
provider
|
|
21
21
|
);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return await documentStore.DEFAULT_ADMIN_ROLE();
|
|
25
|
-
case "issuer":
|
|
26
|
-
return await documentStore.ISSUER_ROLE();
|
|
27
|
-
case "revoker":
|
|
28
|
-
return await documentStore.REVOKER_ROLE();
|
|
29
|
-
default:
|
|
30
|
-
throw new Error("Invalid role");
|
|
22
|
+
if (typeof documentStore[role] !== "function") {
|
|
23
|
+
throw new Error(`Invalid role: ${role}`);
|
|
31
24
|
}
|
|
25
|
+
return await documentStore[role]();
|
|
32
26
|
}, "getRoleString");
|
|
33
|
-
const rolesList = ["
|
|
27
|
+
const rolesList = ["DEFAULT_ADMIN_ROLE", "ISSUER_ROLE", "REVOKER_ROLE"];
|
|
34
28
|
|
|
35
29
|
export { getRoleString, rolesList };
|
|
@@ -4,5 +4,6 @@ export { documentStoreRevokeRole } from './revoke-role';
|
|
|
4
4
|
export { documentStoreGrantRole } from './grant-role';
|
|
5
5
|
export { documentStoreTransferOwnership } from './transferOwnership';
|
|
6
6
|
export { deployDocumentStore } from '../deploy/document-store';
|
|
7
|
+
export { getRoleString } from './document-store-roles';
|
|
7
8
|
export { supportInterfaceIds } from './supportInterfaceIds';
|
|
8
9
|
export { DocumentStore__factory, TransferableDocumentStore__factory } from '@trustvc/document-store';
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { documentStoreRevokeRole } from './revoke-role';
|
|
2
2
|
import { documentStoreGrantRole } from './grant-role';
|
|
3
3
|
import { getRoleString } from './document-store-roles';
|
|
4
|
+
import { checkSupportsInterface } from '../core';
|
|
5
|
+
import { supportInterfaceIds } from './supportInterfaceIds';
|
|
6
|
+
import { TT_DOCUMENT_STORE_ABI } from './tt-document-store-abi';
|
|
7
|
+
import { getEthersContractFromProvider, isV6EthersProvider } from '../utils/ethers';
|
|
8
|
+
import { TransferableDocumentStore__factory, DocumentStore__factory } from '@trustvc/document-store';
|
|
4
9
|
|
|
5
10
|
var __defProp = Object.defineProperty;
|
|
6
11
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -9,29 +14,72 @@ const documentStoreTransferOwnership = /* @__PURE__ */ __name(async (documentSto
|
|
|
9
14
|
if (!signer.provider) throw new Error("Provider is required");
|
|
10
15
|
if (!account) throw new Error("Account is required");
|
|
11
16
|
const ownerAddress = await signer.getAddress();
|
|
12
|
-
const roleString = await getRoleString(documentStoreAddress, "
|
|
17
|
+
const roleString = await getRoleString(documentStoreAddress, "DEFAULT_ADMIN_ROLE", {
|
|
13
18
|
provider: signer.provider
|
|
14
19
|
});
|
|
15
|
-
const
|
|
20
|
+
const Contract = getEthersContractFromProvider(signer.provider);
|
|
21
|
+
const isDocumentStore = await checkSupportsInterface(
|
|
22
|
+
documentStoreAddress,
|
|
23
|
+
supportInterfaceIds.IDocumentStore,
|
|
24
|
+
signer.provider
|
|
25
|
+
);
|
|
26
|
+
const isTransferableDocumentStore = await checkSupportsInterface(
|
|
27
|
+
documentStoreAddress,
|
|
28
|
+
supportInterfaceIds.ITransferableDocumentStore,
|
|
29
|
+
signer.provider
|
|
30
|
+
);
|
|
31
|
+
let documentStoreAbi;
|
|
32
|
+
if (isDocumentStore || isTransferableDocumentStore) {
|
|
33
|
+
const DocumentStoreFactory = isTransferableDocumentStore ? TransferableDocumentStore__factory : DocumentStore__factory;
|
|
34
|
+
documentStoreAbi = DocumentStoreFactory.abi;
|
|
35
|
+
} else {
|
|
36
|
+
documentStoreAbi = TT_DOCUMENT_STORE_ABI;
|
|
37
|
+
}
|
|
38
|
+
const documentStoreContract = new Contract(
|
|
39
|
+
documentStoreAddress,
|
|
40
|
+
documentStoreAbi,
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
signer
|
|
43
|
+
);
|
|
44
|
+
const isV6 = isV6EthersProvider(signer.provider);
|
|
45
|
+
try {
|
|
46
|
+
if (isV6) {
|
|
47
|
+
await documentStoreContract.grantRole.staticCall(roleString, account);
|
|
48
|
+
} else {
|
|
49
|
+
await documentStoreContract.callStatic.grantRole(roleString, account);
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error("callStatic failed:", e);
|
|
53
|
+
throw new Error("Pre-check (callStatic) for grant-role failed");
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
if (isV6) {
|
|
57
|
+
await documentStoreContract.revokeRole.staticCall(roleString, ownerAddress);
|
|
58
|
+
} else {
|
|
59
|
+
await documentStoreContract.callStatic.revokeRole(roleString, ownerAddress);
|
|
60
|
+
}
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error("callStatic failed:", e);
|
|
63
|
+
throw new Error("Pre-check (callStatic) for revoke-role failed");
|
|
64
|
+
}
|
|
65
|
+
const grantTransaction = await documentStoreGrantRole(
|
|
16
66
|
documentStoreAddress,
|
|
17
67
|
roleString,
|
|
18
68
|
account,
|
|
19
69
|
signer,
|
|
20
70
|
options
|
|
21
71
|
);
|
|
22
|
-
|
|
23
|
-
if (!grantTransactionResult) {
|
|
72
|
+
if (!grantTransaction) {
|
|
24
73
|
throw new Error("Grant transaction failed, not proceeding with revoke transaction");
|
|
25
74
|
}
|
|
26
|
-
const revokeTransaction = documentStoreRevokeRole(
|
|
75
|
+
const revokeTransaction = await documentStoreRevokeRole(
|
|
27
76
|
documentStoreAddress,
|
|
28
77
|
roleString,
|
|
29
78
|
ownerAddress,
|
|
30
79
|
signer,
|
|
31
80
|
options
|
|
32
81
|
);
|
|
33
|
-
|
|
34
|
-
if (!revokeTransactionResult) {
|
|
82
|
+
if (!revokeTransaction) {
|
|
35
83
|
throw new Error("Revoke transaction failed");
|
|
36
84
|
}
|
|
37
85
|
return { grantTransaction, revokeTransaction };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { v4ComputeInterfaceId, v4ComputeTitleEscrowAddress, v4ContractAddress, v4Contracts, v4EncodeInitParams, v4GetEventFromReceipt, v4RoleHash, v4SupportInterfaceIds, v4Utils } from './token-registry-v4';
|
|
2
2
|
export { v5ComputeInterfaceId, v5ContractAddress, v5Contracts, v5EncodeInitParams, v5GetEventFromReceipt, v5RoleHash, v5SupportInterfaceIds, v5Utils } from './token-registry-v5';
|
|
3
|
-
export { DocumentStore__factory, TransferableDocumentStore__factory, deployDocumentStore, documentStoreGrantRole, documentStoreIssue, documentStoreRevoke, documentStoreRevokeRole } from './document-store';
|
|
3
|
+
export { DocumentStore__factory, TransferableDocumentStore__factory, deployDocumentStore, documentStoreGrantRole, documentStoreIssue, documentStoreRevoke, documentStoreRevokeRole, documentStoreTransferOwnership, getRoleString } from './document-store';
|
|
4
4
|
export * from './token-registry-functions';
|
|
5
5
|
export * from './core';
|
|
6
6
|
export * from './open-attestation';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import forge from 'node-forge';
|
|
2
|
+
import { ENCRYPTION_PARAMETERS, decodeDocument } from './utils';
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
const decryptString = /* @__PURE__ */ __name(({ cipherText, tag, iv, key, type }) => {
|
|
7
|
+
if (type !== ENCRYPTION_PARAMETERS.version) {
|
|
8
|
+
throw new Error(`Expecting version ${ENCRYPTION_PARAMETERS.version} but got ${type}`);
|
|
9
|
+
}
|
|
10
|
+
const keyBytestring = forge.util.hexToBytes(key);
|
|
11
|
+
const cipherTextBytestring = forge.util.decode64(cipherText);
|
|
12
|
+
const ivBytestring = forge.util.decode64(iv);
|
|
13
|
+
const tagBytestring = forge.util.decode64(tag);
|
|
14
|
+
const decipher = forge.cipher.createDecipher("AES-GCM", keyBytestring);
|
|
15
|
+
decipher.start({
|
|
16
|
+
iv: ivBytestring,
|
|
17
|
+
tagLength: ENCRYPTION_PARAMETERS.tagLength,
|
|
18
|
+
tag: forge.util.createBuffer(tagBytestring, "raw")
|
|
19
|
+
});
|
|
20
|
+
decipher.update(forge.util.createBuffer(cipherTextBytestring, "raw"));
|
|
21
|
+
const success = decipher.finish();
|
|
22
|
+
if (!success) {
|
|
23
|
+
throw new Error("Error decrypting message");
|
|
24
|
+
}
|
|
25
|
+
return decodeDocument(decipher.output.data);
|
|
26
|
+
}, "decryptString");
|
|
27
|
+
|
|
28
|
+
export { decryptString };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import forge from 'node-forge';
|
|
2
|
+
import { encodeDocument, ENCRYPTION_PARAMETERS, generateEncryptionKey } from './utils';
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
const generateIv = /* @__PURE__ */ __name((ivLengthInBits = ENCRYPTION_PARAMETERS.ivLength) => {
|
|
7
|
+
const iv = forge.random.getBytesSync(ivLengthInBits / 8);
|
|
8
|
+
return forge.util.encode64(iv);
|
|
9
|
+
}, "generateIv");
|
|
10
|
+
const makeCipher = /* @__PURE__ */ __name((encryptionKey = generateEncryptionKey()) => {
|
|
11
|
+
const iv = generateIv();
|
|
12
|
+
const cipher = forge.cipher.createCipher(
|
|
13
|
+
ENCRYPTION_PARAMETERS.algorithm,
|
|
14
|
+
forge.util.hexToBytes(encryptionKey)
|
|
15
|
+
);
|
|
16
|
+
cipher.start({
|
|
17
|
+
iv: forge.util.decode64(iv),
|
|
18
|
+
tagLength: ENCRYPTION_PARAMETERS.tagLength
|
|
19
|
+
});
|
|
20
|
+
return { cipher, encryptionKey, iv };
|
|
21
|
+
}, "makeCipher");
|
|
22
|
+
const encryptString = /* @__PURE__ */ __name((document, key) => {
|
|
23
|
+
if (typeof document !== "string") {
|
|
24
|
+
throw new Error("encryptString only accepts strings");
|
|
25
|
+
}
|
|
26
|
+
const { cipher, encryptionKey, iv } = makeCipher(key);
|
|
27
|
+
const buffer = forge.util.createBuffer(encodeDocument(document));
|
|
28
|
+
cipher.update(buffer);
|
|
29
|
+
cipher.finish();
|
|
30
|
+
const encryptedMessage = forge.util.encode64(cipher.output.data);
|
|
31
|
+
const tag = forge.util.encode64(cipher.mode.tag.data);
|
|
32
|
+
return {
|
|
33
|
+
cipherText: encryptedMessage,
|
|
34
|
+
iv,
|
|
35
|
+
tag,
|
|
36
|
+
key: encryptionKey,
|
|
37
|
+
type: ENCRYPTION_PARAMETERS.version
|
|
38
|
+
};
|
|
39
|
+
}, "encryptString");
|
|
40
|
+
|
|
41
|
+
export { encryptString };
|
|
@@ -1,6 +1,41 @@
|
|
|
1
|
+
import forge from 'node-forge';
|
|
1
2
|
import { utils } from '@tradetrust-tt/tradetrust';
|
|
2
3
|
export { SUPPORTED_SIGNING_ALGORITHM, SchemaId, getData as getDataV2, isSchemaValidationError, obfuscateDocument, validateSchema } from '@tradetrust-tt/tradetrust';
|
|
3
4
|
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
const ENCRYPTION_PARAMETERS = Object.freeze({
|
|
8
|
+
algorithm: "AES-GCM",
|
|
9
|
+
keyLength: 256,
|
|
10
|
+
// Key length in bits
|
|
11
|
+
ivLength: 96,
|
|
12
|
+
// IV length in bits: NIST suggests 12 bytes
|
|
13
|
+
tagLength: 128,
|
|
14
|
+
// GCM authentication tag length in bits, see link above for explanation
|
|
15
|
+
version: "OPEN-ATTESTATION-TYPE-1"
|
|
16
|
+
// Type 1 using the above params without compression
|
|
17
|
+
});
|
|
18
|
+
const generateEncryptionKey = /* @__PURE__ */ __name((keyLengthInBits = ENCRYPTION_PARAMETERS.keyLength) => {
|
|
19
|
+
if (!Number.isInteger(keyLengthInBits) || ![128, 192, 256].includes(keyLengthInBits)) {
|
|
20
|
+
throw new Error("keyLengthInBits must be one of 128, 192, or 256");
|
|
21
|
+
}
|
|
22
|
+
const encryptionKey = forge.random.getBytesSync(keyLengthInBits / 8);
|
|
23
|
+
return forge.util.bytesToHex(encryptionKey);
|
|
24
|
+
}, "generateEncryptionKey");
|
|
25
|
+
const encodeDocument = /* @__PURE__ */ __name((document) => {
|
|
26
|
+
const bytes = forge.util.encodeUtf8(document);
|
|
27
|
+
const standard = forge.util.encode64(bytes);
|
|
28
|
+
const s = standard.replace(/\+/g, "-").replace(/\//g, "_");
|
|
29
|
+
const trim = s.endsWith("==") ? 2 : s.endsWith("=") ? 1 : 0;
|
|
30
|
+
return trim ? s.slice(0, -trim) : s;
|
|
31
|
+
}, "encodeDocument");
|
|
32
|
+
const decodeDocument = /* @__PURE__ */ __name((encoded) => {
|
|
33
|
+
let normalized = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
34
|
+
const pad = normalized.length % 4;
|
|
35
|
+
if (pad) normalized += "=".repeat(4 - pad);
|
|
36
|
+
const decoded = forge.util.decode64(normalized);
|
|
37
|
+
return forge.util.decodeUtf8(decoded);
|
|
38
|
+
}, "decodeDocument");
|
|
4
39
|
const {
|
|
5
40
|
isTransferableAsset,
|
|
6
41
|
isDocumentRevokable,
|
|
@@ -17,4 +52,4 @@ const {
|
|
|
17
52
|
getTemplateURL
|
|
18
53
|
} = utils;
|
|
19
54
|
|
|
20
|
-
export { diagnose, getAssetId, getDocumentData, getIssuerAddress, getTemplateURL, isDocumentRevokable, isRawV2Document, isRawV3Document, isSignedWrappedV2Document, isSignedWrappedV3Document, isTransferableAsset, isWrappedV2Document, isWrappedV3Document };
|
|
55
|
+
export { ENCRYPTION_PARAMETERS, decodeDocument, diagnose, encodeDocument, generateEncryptionKey, getAssetId, getDocumentData, getIssuerAddress, getTemplateURL, isDocumentRevokable, isRawV2Document, isRawV3Document, isSignedWrappedV2Document, isSignedWrappedV3Document, isTransferableAsset, isWrappedV2Document, isWrappedV3Document };
|
|
@@ -4,6 +4,7 @@ export { documentStoreRevokeRole } from './revoke-role.js';
|
|
|
4
4
|
export { documentStoreGrantRole } from './grant-role.js';
|
|
5
5
|
export { documentStoreTransferOwnership } from './transferOwnership.js';
|
|
6
6
|
export { deployDocumentStore } from '../deploy/document-store.js';
|
|
7
|
+
export { getRoleString } from './document-store-roles.js';
|
|
7
8
|
export { supportInterfaceIds } from './supportInterfaceIds.js';
|
|
8
9
|
export { DocumentStore__factory, TransferableDocumentStore__factory } from '@trustvc/document-store';
|
|
9
10
|
import 'ethersV6';
|
|
@@ -17,14 +17,14 @@ import '../token-registry-functions/types.js';
|
|
|
17
17
|
* @param {string} account - The account to transfer ownership to.
|
|
18
18
|
* @param {SignerV5 | SignerV6} signer - Signer instance (Ethers v5 or v6) that authorizes the transfer ownership transaction.
|
|
19
19
|
* @param {CommandOptions} options - Optional transaction metadata including gas values and chain ID.
|
|
20
|
-
* @returns {Promise<{grantTransaction:
|
|
20
|
+
* @returns {Promise<{grantTransaction: ContractTransactionV5 | ContractTransactionV6; revokeTransaction: ContractTransactionV5 | ContractTransactionV6}>} A promise resolving to the transaction result from the grant and revoke role calls.
|
|
21
21
|
* @throws {Error} If the document store address or signer provider is not provided.
|
|
22
22
|
* @throws {Error} If the role is invalid.
|
|
23
|
-
* @throws {Error} If the `callStatic.
|
|
23
|
+
* @throws {Error} If either the `callStatic.grantRole` or `callStatic.revokeRole` pre-check fails.
|
|
24
24
|
*/
|
|
25
25
|
declare const documentStoreTransferOwnership: (documentStoreAddress: string, account: string, signer: Signer | Signer$1, options?: CommandOptions) => Promise<{
|
|
26
|
-
grantTransaction:
|
|
27
|
-
revokeTransaction:
|
|
26
|
+
grantTransaction: ContractTransaction | ContractTransactionResponse;
|
|
27
|
+
revokeTransaction: ContractTransaction | ContractTransactionResponse;
|
|
28
28
|
}>;
|
|
29
29
|
|
|
30
30
|
export { documentStoreTransferOwnership };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,16 +15,9 @@ export { documentStoreIssue } from './document-store/issue.js';
|
|
|
15
15
|
export { documentStoreRevoke } from './document-store/revoke.js';
|
|
16
16
|
export { documentStoreRevokeRole } from './document-store/revoke-role.js';
|
|
17
17
|
export { documentStoreGrantRole } from './document-store/grant-role.js';
|
|
18
|
-
export {
|
|
19
|
-
export { networkCurrency, networkName, networkType, networks } from './utils/network/index.js';
|
|
20
|
-
export { generate12ByteNonce, generate32ByteKey, stringToUint8Array } from './utils/stringUtils/index.js';
|
|
21
|
-
export { CHAIN_ID, SUPPORTED_CHAINS, chainInfo } from './utils/supportedChains/index.js';
|
|
22
|
-
export { errorMessages } from './utils/errorMessages/index.js';
|
|
23
|
-
export { WrappedOrSignedOpenAttestationDocument, getChainId, getObfuscatedData, getTokenId, getTokenRegistryAddress, getTransferableRecordsCredentialStatus, isObfuscated, isTransferableRecord } from './utils/documents/index.js';
|
|
24
|
-
export { GasStationFeeData, GasStationFunction, calculateMaxFee, gasStation, scaleBigNumber } from './utils/gasStation/index.js';
|
|
25
|
-
export { AwsKmsSigner, AwsKmsSignerCredentials } from '@tradetrust-tt/ethers-aws-kms-signer';
|
|
26
|
-
export { gaEvent, gaPageView, validateGaEvent, validateGtag, validatePageViewEvent } from './utils/analytics/analytics.js';
|
|
18
|
+
export { documentStoreTransferOwnership } from './document-store/transferOwnership.js';
|
|
27
19
|
export { deployDocumentStore } from './deploy/document-store.js';
|
|
20
|
+
export { getRoleString } from './document-store/document-store-roles.js';
|
|
28
21
|
export { DocumentStore__factory, TransferableDocumentStore__factory } from '@trustvc/document-store';
|
|
29
22
|
export { nominate, transferBeneficiary, transferHolder, transferOwners } from './token-registry-functions/transfer.js';
|
|
30
23
|
export { rejectTransferBeneficiary, rejectTransferHolder, rejectTransferOwners } from './token-registry-functions/rejectTransfers.js';
|
|
@@ -43,10 +36,12 @@ export { EndorsementChain, ParsedLog, TitleEscrowTransferEvent, TitleEscrowTrans
|
|
|
43
36
|
export { TitleEscrowInterface, checkSupportsInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion } from './core/endorsement-chain/useEndorsementChain.js';
|
|
44
37
|
export { DocumentBuilder, RenderMethod, SignOptions, W3CTransferableRecordsConfig, W3CVerifiableDocumentConfig, qrCode } from './core/documentBuilder.js';
|
|
45
38
|
export { signOA } from './open-attestation/sign.js';
|
|
46
|
-
export { KeyPair } from './open-attestation/types.js';
|
|
47
|
-
export { diagnose, getAssetId, getDocumentData, getIssuerAddress, getTemplateURL, isDocumentRevokable, isRawV2Document, isRawV3Document, isSignedWrappedV2Document, isSignedWrappedV3Document, isTransferableAsset, isWrappedV2Document, isWrappedV3Document } from './open-attestation/utils.js';
|
|
39
|
+
export { IEncryptionResults, KeyPair } from './open-attestation/types.js';
|
|
40
|
+
export { ENCRYPTION_PARAMETERS, decodeDocument, diagnose, encodeDocument, generateEncryptionKey, getAssetId, getDocumentData, getIssuerAddress, getTemplateURL, isDocumentRevokable, isRawV2Document, isRawV3Document, isSignedWrappedV2Document, isSignedWrappedV3Document, isTransferableAsset, isWrappedV2Document, isWrappedV3Document } from './open-attestation/utils.js';
|
|
48
41
|
export { verifyOASignature } from './open-attestation/verify.js';
|
|
49
42
|
export { wrapOADocument, wrapOADocumentV2, wrapOADocuments, wrapOADocumentsV2 } from './open-attestation/wrap.js';
|
|
43
|
+
export { encryptString } from './open-attestation/encrypt.js';
|
|
44
|
+
export { decryptString } from './open-attestation/decrypt.js';
|
|
50
45
|
export { openAttestationVerifiers, verifiers, w3cVerifiers } from './verify/verify.js';
|
|
51
46
|
export { i as fragments } from './index-ZZ1UYFI0.js';
|
|
52
47
|
export { OpencertsRegistryCode, OpencertsRegistryVerificationInvalidData, OpencertsRegistryVerificationInvalidDataArray, OpencertsRegistryVerificationValidData, OpencertsRegistryVerificationValidDataArray, OpencertsRegistryVerifierInvalidFragmentV2, OpencertsRegistryVerifierInvalidFragmentV3, OpencertsRegistryVerifierValidFragmentV2, OpencertsRegistryVerifierValidFragmentV3, OpencertsRegistryVerifierVerificationFragment, Registry, RegistryEntry, getOpencertsRegistryVerifierFragment, isValidOpenCert, name, registryVerifier, type, verifyOpenCertSignature } from './open-cert/verify.js';
|
|
@@ -59,6 +54,15 @@ export { PrivateKeyPair } from '@trustvc/w3c-issuer';
|
|
|
59
54
|
export { i as vc } from './index-1ws_BWZW.js';
|
|
60
55
|
export { verifyW3CSignature } from './w3c/verify.js';
|
|
61
56
|
export { deriveW3C } from './w3c/derive.js';
|
|
57
|
+
export { OAErrorMessageHandling, errorMessageHandling, interpretFragments, w3cCredentialStatusRevoked, w3cCredentialStatusSuspended } from './utils/fragment/index.js';
|
|
58
|
+
export { networkCurrency, networkName, networkType, networks } from './utils/network/index.js';
|
|
59
|
+
export { generate12ByteNonce, generate32ByteKey, stringToUint8Array } from './utils/stringUtils/index.js';
|
|
60
|
+
export { CHAIN_ID, SUPPORTED_CHAINS, chainInfo } from './utils/supportedChains/index.js';
|
|
61
|
+
export { errorMessages } from './utils/errorMessages/index.js';
|
|
62
|
+
export { WrappedOrSignedOpenAttestationDocument, getChainId, getObfuscatedData, getTokenId, getTokenRegistryAddress, getTransferableRecordsCredentialStatus, isObfuscated, isTransferableRecord } from './utils/documents/index.js';
|
|
63
|
+
export { GasStationFeeData, GasStationFunction, calculateMaxFee, gasStation, scaleBigNumber } from './utils/gasStation/index.js';
|
|
64
|
+
export { AwsKmsSigner, AwsKmsSignerCredentials } from '@tradetrust-tt/ethers-aws-kms-signer';
|
|
65
|
+
export { gaEvent, gaPageView, validateGaEvent, validateGtag, validatePageViewEvent } from './utils/analytics/analytics.js';
|
|
62
66
|
export { CustomDnsResolver, IDNSQueryResponse, IDNSRecord, OpenAttestationDNSTextRecord, OpenAttestationDnsDidRecord, defaultDnsResolvers, getDnsDidRecords, getDocumentStoreRecords, parseDnsDidResults, parseDocumentStoreResults, parseOpenAttestationRecord, queryDns } from '@tradetrust-tt/dnsprove';
|
|
63
67
|
export { OpenAttestationDocument, SUPPORTED_SIGNING_ALGORITHM, SchemaId, SignedWrappedDocument, WrappedDocument, getData as getDataV2, isSchemaValidationError, obfuscateDocument, v2, v3, validateSchema, __unsafe__use__it__at__your__own__risks__wrapDocument as wrapOADocumentV3, __unsafe__use__it__at__your__own__risks__wrapDocuments as wrapOADocumentsV3 } from '@tradetrust-tt/tradetrust';
|
|
64
68
|
export { DiagnoseError } from '@tradetrust-tt/tradetrust/dist/types/shared/utils';
|
|
@@ -72,7 +76,6 @@ import '@tradetrust-tt/token-registry-v5/contracts';
|
|
|
72
76
|
import 'ethersV6';
|
|
73
77
|
import './document-store/types.js';
|
|
74
78
|
import './token-registry-functions/types.js';
|
|
75
|
-
import '@trustvc/w3c-credential-status';
|
|
76
79
|
import '@ethersproject/abstract-provider';
|
|
77
80
|
import 'ethers/lib/utils';
|
|
78
81
|
import '@ethersproject/abstract-signer';
|
|
@@ -90,3 +93,4 @@ import './verify/fragments/issuer-identity/w3cIssuerIdentity.js';
|
|
|
90
93
|
import './verify/fragments/document-status/w3cEmptyCredentialStatus/index.js';
|
|
91
94
|
import 'runtypes';
|
|
92
95
|
import '@trustvc/w3c-context';
|
|
96
|
+
import '@trustvc/w3c-credential-status';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IEncryptionResults } from './types.js';
|
|
2
|
+
import '@tradetrust-tt/tradetrust';
|
|
3
|
+
import '@tradetrust-tt/tradetrust/dist/types/shared/utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Decrypts a given ciphertext along with its associated variables.
|
|
7
|
+
* @param {IEncryptionResults} encryptionResults - Encryption result object containing cipherText (base64), tag (base64), iv (base64), key (hex), and type.
|
|
8
|
+
* @returns {string} Decrypted plaintext string.
|
|
9
|
+
*/
|
|
10
|
+
declare const decryptString: ({ cipherText, tag, iv, key, type }: IEncryptionResults) => string;
|
|
11
|
+
|
|
12
|
+
export { decryptString };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IEncryptionResults } from './types.js';
|
|
2
|
+
import '@tradetrust-tt/tradetrust';
|
|
3
|
+
import '@tradetrust-tt/tradetrust/dist/types/shared/utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Encrypts a given string with symmetric AES-GCM.
|
|
7
|
+
* @param {string} document - Input string to encrypt.
|
|
8
|
+
* @param {string} [key] - Optional encryption key in hexadecimal (64 chars for 256-bit). If omitted, a key is generated.
|
|
9
|
+
* @returns {IEncryptionResults} Object with cipherText (base64), iv (base64), tag (base64), key (hex), and type.
|
|
10
|
+
*/
|
|
11
|
+
declare const encryptString: (document: string, key?: string) => IEncryptionResults;
|
|
12
|
+
|
|
13
|
+
export { encryptString };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { signOA } from './sign.js';
|
|
2
|
-
export { KeyPair } from './types.js';
|
|
3
|
-
export { diagnose, getAssetId, getDocumentData, getIssuerAddress, getTemplateURL, isDocumentRevokable, isRawV2Document, isRawV3Document, isSignedWrappedV2Document, isSignedWrappedV3Document, isTransferableAsset, isWrappedV2Document, isWrappedV3Document } from './utils.js';
|
|
2
|
+
export { IEncryptionResults, KeyPair } from './types.js';
|
|
3
|
+
export { ENCRYPTION_PARAMETERS, decodeDocument, diagnose, encodeDocument, generateEncryptionKey, getAssetId, getDocumentData, getIssuerAddress, getTemplateURL, isDocumentRevokable, isRawV2Document, isRawV3Document, isSignedWrappedV2Document, isSignedWrappedV3Document, isTransferableAsset, isWrappedV2Document, isWrappedV3Document } from './utils.js';
|
|
4
4
|
export { verifyOASignature } from './verify.js';
|
|
5
5
|
export { wrapOADocument, wrapOADocumentV2, wrapOADocuments, wrapOADocumentsV2 } from './wrap.js';
|
|
6
|
+
export { encryptString } from './encrypt.js';
|
|
7
|
+
export { decryptString } from './decrypt.js';
|
|
6
8
|
export { OpenAttestationDocument, SUPPORTED_SIGNING_ALGORITHM, SchemaId, SignedWrappedDocument, WrappedDocument, getData as getDataV2, isSchemaValidationError, obfuscateDocument, v2, v3, validateSchema, __unsafe__use__it__at__your__own__risks__wrapDocument as wrapOADocumentV3, __unsafe__use__it__at__your__own__risks__wrapDocuments as wrapOADocumentsV3 } from '@tradetrust-tt/tradetrust';
|
|
7
9
|
export { DiagnoseError } from '@tradetrust-tt/tradetrust/dist/types/shared/utils';
|
|
8
10
|
import '@ethersproject/abstract-signer';
|
|
@@ -5,5 +5,12 @@ type KeyPair = {
|
|
|
5
5
|
public: string;
|
|
6
6
|
private: string;
|
|
7
7
|
};
|
|
8
|
+
interface IEncryptionResults {
|
|
9
|
+
cipherText: string;
|
|
10
|
+
iv: string;
|
|
11
|
+
tag: string;
|
|
12
|
+
key: string;
|
|
13
|
+
type: string;
|
|
14
|
+
}
|
|
8
15
|
|
|
9
|
-
export type { KeyPair };
|
|
16
|
+
export type { IEncryptionResults, KeyPair };
|
|
@@ -7,6 +7,37 @@ import * as _tradetrust_tt_tradetrust_dist_types_2_0_types from '@tradetrust-tt/
|
|
|
7
7
|
import * as _tradetrust_tt_tradetrust_dist_types___generated___schema_2_0 from '@tradetrust-tt/tradetrust/dist/types/__generated__/schema.2.0';
|
|
8
8
|
import * as _tradetrust_tt_tradetrust_dist_types_shared_utils__types_diagnose from '@tradetrust-tt/tradetrust/dist/types/shared/utils/@types/diagnose';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Default options for OA document encryption (AES-GCM).
|
|
12
|
+
* {@link https://crypto.stackexchange.com/questions/26783/ciphertext-and-tag-size-and-iv-transmission-with-aes-in-gcm-mode/26787|here}
|
|
13
|
+
*/
|
|
14
|
+
declare const ENCRYPTION_PARAMETERS: Readonly<{
|
|
15
|
+
readonly algorithm: "AES-GCM";
|
|
16
|
+
readonly keyLength: 256;
|
|
17
|
+
readonly ivLength: 96;
|
|
18
|
+
readonly tagLength: 128;
|
|
19
|
+
readonly version: "OPEN-ATTESTATION-TYPE-1";
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Generates a random key represented as a hexadecimal string.
|
|
23
|
+
* @param {number} [keyLengthInBits] - Key length in bits.
|
|
24
|
+
* @returns {string} Hexadecimal-encoded encryption key.
|
|
25
|
+
*/
|
|
26
|
+
declare const generateEncryptionKey: (keyLengthInBits?: number) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Encode document string to URL-safe base64 (base64url: UTF-8 then base64 with +→-, /→_, no padding).
|
|
29
|
+
* Safe for use in query strings and JSON without further encoding.
|
|
30
|
+
* @param {string} document - Plain text document to encode.
|
|
31
|
+
* @returns {string} Base64url-encoded string.
|
|
32
|
+
*/
|
|
33
|
+
declare const encodeDocument: (document: string) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Decode base64url-encoded document string back to UTF-8.
|
|
36
|
+
* Accepts both base64url (no padding, - and _) and standard base64 for backwards compatibility.
|
|
37
|
+
* @param {string} encoded - Base64- or base64url-encoded string to decode.
|
|
38
|
+
* @returns {string} Decoded UTF-8 plain text.
|
|
39
|
+
*/
|
|
40
|
+
declare const decodeDocument: (encoded: string) => string;
|
|
10
41
|
declare const isTransferableAsset: (document: any) => boolean;
|
|
11
42
|
declare const isDocumentRevokable: (document: any) => boolean;
|
|
12
43
|
declare const getAssetId: (document: any) => string;
|
|
@@ -39,4 +70,4 @@ declare const diagnose: ({ version, kind, document, debug, mode, }: {
|
|
|
39
70
|
}) => utils.DiagnoseError[];
|
|
40
71
|
declare const getTemplateURL: (document: any) => string | undefined;
|
|
41
72
|
|
|
42
|
-
export { diagnose, getAssetId, getDocumentData, getIssuerAddress, getTemplateURL, isDocumentRevokable, isRawV2Document, isRawV3Document, isSignedWrappedV2Document, isSignedWrappedV3Document, isTransferableAsset, isWrappedV2Document, isWrappedV3Document };
|
|
73
|
+
export { ENCRYPTION_PARAMETERS, decodeDocument, diagnose, encodeDocument, generateEncryptionKey, getAssetId, getDocumentData, getIssuerAddress, getTemplateURL, isDocumentRevokable, isRawV2Document, isRawV3Document, isSignedWrappedV2Document, isSignedWrappedV3Document, isTransferableAsset, isWrappedV2Document, isWrappedV3Document };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trustvc/trustvc",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"description": "TrustVC library",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -131,6 +131,7 @@
|
|
|
131
131
|
"ethersV6": "npm:ethers@^6.14.4",
|
|
132
132
|
"js-sha3": "^0.9.3",
|
|
133
133
|
"node-fetch": "^2.7.0",
|
|
134
|
+
"node-forge": "^1.3.3",
|
|
134
135
|
"ts-chacha20": "^1.2.0"
|
|
135
136
|
},
|
|
136
137
|
"devDependencies": {
|
|
@@ -149,6 +150,7 @@
|
|
|
149
150
|
"@types/lodash": "^4.17.16",
|
|
150
151
|
"@types/mocha": "^10.0.10",
|
|
151
152
|
"@types/node": "^18.19.86",
|
|
153
|
+
"@types/node-forge": "^1.3.14",
|
|
152
154
|
"@types/node-fetch": "^2.6.12",
|
|
153
155
|
"@vitest/coverage-v8": "^1.6.1",
|
|
154
156
|
"concurrently": "^9.2.0",
|