@trustvc/trustvc 2.9.0 → 2.9.1

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.
@@ -21,18 +21,12 @@ const getRoleString = /* @__PURE__ */ __name(async (documentStoreAddress, role,
21
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
22
  provider
23
23
  );
24
- switch (role) {
25
- case "admin":
26
- return await documentStore.DEFAULT_ADMIN_ROLE();
27
- case "issuer":
28
- return await documentStore.ISSUER_ROLE();
29
- case "revoker":
30
- return await documentStore.REVOKER_ROLE();
31
- default:
32
- throw new Error("Invalid role");
24
+ if (typeof documentStore[role] !== "function") {
25
+ throw new Error(`Invalid role: ${role}`);
33
26
  }
27
+ return await documentStore[role]();
34
28
  }, "getRoleString");
35
- const rolesList = ["admin", "issuer", "revoker"];
29
+ const rolesList = ["DEFAULT_ADMIN_ROLE", "ISSUER_ROLE", "REVOKER_ROLE"];
36
30
 
37
31
  exports.getRoleString = getRoleString;
38
32
  exports.rolesList = rolesList;
@@ -6,6 +6,7 @@ var revokeRole = require('./revoke-role');
6
6
  var grantRole = require('./grant-role');
7
7
  var transferOwnership = require('./transferOwnership');
8
8
  var documentStore$1 = require('../deploy/document-store');
9
+ var documentStoreRoles = require('./document-store-roles');
9
10
  var supportInterfaceIds = require('./supportInterfaceIds');
10
11
  var documentStore = require('@trustvc/document-store');
11
12
 
@@ -35,6 +36,10 @@ Object.defineProperty(exports, "deployDocumentStore", {
35
36
  enumerable: true,
36
37
  get: function () { return documentStore$1.deployDocumentStore; }
37
38
  });
39
+ Object.defineProperty(exports, "getRoleString", {
40
+ enumerable: true,
41
+ get: function () { return documentStoreRoles.getRoleString; }
42
+ });
38
43
  Object.defineProperty(exports, "supportInterfaceIds", {
39
44
  enumerable: true,
40
45
  get: function () { return supportInterfaceIds.supportInterfaceIds; }
@@ -3,6 +3,11 @@
3
3
  var revokeRole = require('./revoke-role');
4
4
  var grantRole = require('./grant-role');
5
5
  var documentStoreRoles = require('./document-store-roles');
6
+ var core = require('../core');
7
+ var supportInterfaceIds = require('./supportInterfaceIds');
8
+ var ttDocumentStoreAbi = require('./tt-document-store-abi');
9
+ var ethers = require('../utils/ethers');
10
+ var documentStore = require('@trustvc/document-store');
6
11
 
7
12
  var __defProp = Object.defineProperty;
8
13
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -11,29 +16,72 @@ const documentStoreTransferOwnership = /* @__PURE__ */ __name(async (documentSto
11
16
  if (!signer.provider) throw new Error("Provider is required");
12
17
  if (!account) throw new Error("Account is required");
13
18
  const ownerAddress = await signer.getAddress();
14
- const roleString = await documentStoreRoles.getRoleString(documentStoreAddress, "admin", {
19
+ const roleString = await documentStoreRoles.getRoleString(documentStoreAddress, "DEFAULT_ADMIN_ROLE", {
15
20
  provider: signer.provider
16
21
  });
17
- const grantTransaction = grantRole.documentStoreGrantRole(
22
+ const Contract = ethers.getEthersContractFromProvider(signer.provider);
23
+ const isDocumentStore = await core.checkSupportsInterface(
24
+ documentStoreAddress,
25
+ supportInterfaceIds.supportInterfaceIds.IDocumentStore,
26
+ signer.provider
27
+ );
28
+ const isTransferableDocumentStore = await core.checkSupportsInterface(
29
+ documentStoreAddress,
30
+ supportInterfaceIds.supportInterfaceIds.ITransferableDocumentStore,
31
+ signer.provider
32
+ );
33
+ let documentStoreAbi;
34
+ if (isDocumentStore || isTransferableDocumentStore) {
35
+ const DocumentStoreFactory = isTransferableDocumentStore ? documentStore.TransferableDocumentStore__factory : documentStore.DocumentStore__factory;
36
+ documentStoreAbi = DocumentStoreFactory.abi;
37
+ } else {
38
+ documentStoreAbi = ttDocumentStoreAbi.TT_DOCUMENT_STORE_ABI;
39
+ }
40
+ const documentStoreContract = new Contract(
41
+ documentStoreAddress,
42
+ documentStoreAbi,
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ signer
45
+ );
46
+ const isV6 = ethers.isV6EthersProvider(signer.provider);
47
+ try {
48
+ if (isV6) {
49
+ await documentStoreContract.grantRole.staticCall(roleString, account);
50
+ } else {
51
+ await documentStoreContract.callStatic.grantRole(roleString, account);
52
+ }
53
+ } catch (e) {
54
+ console.error("callStatic failed:", e);
55
+ throw new Error("Pre-check (callStatic) for grant-role failed");
56
+ }
57
+ try {
58
+ if (isV6) {
59
+ await documentStoreContract.revokeRole.staticCall(roleString, ownerAddress);
60
+ } else {
61
+ await documentStoreContract.callStatic.revokeRole(roleString, ownerAddress);
62
+ }
63
+ } catch (e) {
64
+ console.error("callStatic failed:", e);
65
+ throw new Error("Pre-check (callStatic) for revoke-role failed");
66
+ }
67
+ const grantTransaction = await grantRole.documentStoreGrantRole(
18
68
  documentStoreAddress,
19
69
  roleString,
20
70
  account,
21
71
  signer,
22
72
  options
23
73
  );
24
- const grantTransactionResult = await grantTransaction;
25
- if (!grantTransactionResult) {
74
+ if (!grantTransaction) {
26
75
  throw new Error("Grant transaction failed, not proceeding with revoke transaction");
27
76
  }
28
- const revokeTransaction = revokeRole.documentStoreRevokeRole(
77
+ const revokeTransaction = await revokeRole.documentStoreRevokeRole(
29
78
  documentStoreAddress,
30
79
  roleString,
31
80
  ownerAddress,
32
81
  signer,
33
82
  options
34
83
  );
35
- const revokeTransactionResult = await revokeTransaction;
36
- if (!revokeTransactionResult) {
84
+ if (!revokeTransaction) {
37
85
  throw new Error("Revoke transaction failed");
38
86
  }
39
87
  return { grantTransaction, revokeTransaction };
package/dist/cjs/index.js CHANGED
@@ -110,6 +110,14 @@ Object.defineProperty(exports, "documentStoreRevokeRole", {
110
110
  enumerable: true,
111
111
  get: function () { return documentStore.documentStoreRevokeRole; }
112
112
  });
113
+ Object.defineProperty(exports, "documentStoreTransferOwnership", {
114
+ enumerable: true,
115
+ get: function () { return documentStore.documentStoreTransferOwnership; }
116
+ });
117
+ Object.defineProperty(exports, "getRoleString", {
118
+ enumerable: true,
119
+ get: function () { return documentStore.getRoleString; }
120
+ });
113
121
  Object.keys(tokenRegistryFunctions).forEach(function (k) {
114
122
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
115
123
  enumerable: true,
@@ -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
- switch (role) {
23
- case "admin":
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 = ["admin", "issuer", "revoker"];
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, "admin", {
17
+ const roleString = await getRoleString(documentStoreAddress, "DEFAULT_ADMIN_ROLE", {
13
18
  provider: signer.provider
14
19
  });
15
- const grantTransaction = documentStoreGrantRole(
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
- const grantTransactionResult = await grantTransaction;
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
- const revokeTransactionResult = await revokeTransaction;
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';
@@ -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: Promise<ContractTransactionV5 | ContractTransactionV6>; revokeTransaction: Promise<ContractTransactionV5 | ContractTransactionV6>}>} A promise resolving to the transaction result from the grant and revoke role calls.
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.revokeRole` fails as a pre-check.
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: Promise<ContractTransaction | ContractTransactionResponse>;
27
- revokeTransaction: Promise<ContractTransaction | ContractTransactionResponse>;
26
+ grantTransaction: ContractTransaction | ContractTransactionResponse;
27
+ revokeTransaction: ContractTransaction | ContractTransactionResponse;
28
28
  }>;
29
29
 
30
30
  export { documentStoreTransferOwnership };
@@ -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 { OAErrorMessageHandling, errorMessageHandling, interpretFragments, w3cCredentialStatusRevoked, w3cCredentialStatusSuspended } from './utils/fragment/index.js';
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';
@@ -59,6 +52,15 @@ export { PrivateKeyPair } from '@trustvc/w3c-issuer';
59
52
  export { i as vc } from './index-1ws_BWZW.js';
60
53
  export { verifyW3CSignature } from './w3c/verify.js';
61
54
  export { deriveW3C } from './w3c/derive.js';
55
+ export { OAErrorMessageHandling, errorMessageHandling, interpretFragments, w3cCredentialStatusRevoked, w3cCredentialStatusSuspended } from './utils/fragment/index.js';
56
+ export { networkCurrency, networkName, networkType, networks } from './utils/network/index.js';
57
+ export { generate12ByteNonce, generate32ByteKey, stringToUint8Array } from './utils/stringUtils/index.js';
58
+ export { CHAIN_ID, SUPPORTED_CHAINS, chainInfo } from './utils/supportedChains/index.js';
59
+ export { errorMessages } from './utils/errorMessages/index.js';
60
+ export { WrappedOrSignedOpenAttestationDocument, getChainId, getObfuscatedData, getTokenId, getTokenRegistryAddress, getTransferableRecordsCredentialStatus, isObfuscated, isTransferableRecord } from './utils/documents/index.js';
61
+ export { GasStationFeeData, GasStationFunction, calculateMaxFee, gasStation, scaleBigNumber } from './utils/gasStation/index.js';
62
+ export { AwsKmsSigner, AwsKmsSignerCredentials } from '@tradetrust-tt/ethers-aws-kms-signer';
63
+ export { gaEvent, gaPageView, validateGaEvent, validateGtag, validatePageViewEvent } from './utils/analytics/analytics.js';
62
64
  export { CustomDnsResolver, IDNSQueryResponse, IDNSRecord, OpenAttestationDNSTextRecord, OpenAttestationDnsDidRecord, defaultDnsResolvers, getDnsDidRecords, getDocumentStoreRecords, parseDnsDidResults, parseDocumentStoreResults, parseOpenAttestationRecord, queryDns } from '@tradetrust-tt/dnsprove';
63
65
  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
66
  export { DiagnoseError } from '@tradetrust-tt/tradetrust/dist/types/shared/utils';
@@ -72,7 +74,6 @@ import '@tradetrust-tt/token-registry-v5/contracts';
72
74
  import 'ethersV6';
73
75
  import './document-store/types.js';
74
76
  import './token-registry-functions/types.js';
75
- import '@trustvc/w3c-credential-status';
76
77
  import '@ethersproject/abstract-provider';
77
78
  import 'ethers/lib/utils';
78
79
  import '@ethersproject/abstract-signer';
@@ -90,3 +91,4 @@ import './verify/fragments/issuer-identity/w3cIssuerIdentity.js';
90
91
  import './verify/fragments/document-status/w3cEmptyCredentialStatus/index.js';
91
92
  import 'runtypes';
92
93
  import '@trustvc/w3c-context';
94
+ import '@trustvc/w3c-credential-status';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustvc/trustvc",
3
- "version": "2.9.0",
3
+ "version": "2.9.1",
4
4
  "description": "TrustVC library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",