@trustvc/trustvc 2.6.1 → 2.8.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.
Files changed (41) hide show
  1. package/README.md +217 -0
  2. package/dist/cjs/document-store/contract-interfaces.js +24 -0
  3. package/dist/cjs/document-store/deploy.js +49 -0
  4. package/dist/cjs/document-store/document-store-roles.js +38 -0
  5. package/dist/cjs/document-store/grant-role.js +67 -0
  6. package/dist/cjs/document-store/index.js +49 -0
  7. package/dist/cjs/document-store/issue.js +66 -0
  8. package/dist/cjs/document-store/revoke-role.js +67 -0
  9. package/dist/cjs/document-store/revoke.js +66 -0
  10. package/dist/cjs/document-store/supportInterfaceIds.js +22 -0
  11. package/dist/cjs/document-store/transferOwnership.js +42 -0
  12. package/dist/cjs/document-store/tt-document-store-abi.js +231 -0
  13. package/dist/cjs/document-store/types.js +2 -0
  14. package/dist/cjs/index.js +29 -0
  15. package/dist/esm/document-store/contract-interfaces.js +22 -0
  16. package/dist/esm/document-store/deploy.js +47 -0
  17. package/dist/esm/document-store/document-store-roles.js +35 -0
  18. package/dist/esm/document-store/grant-role.js +65 -0
  19. package/dist/esm/document-store/index.js +8 -0
  20. package/dist/esm/document-store/issue.js +64 -0
  21. package/dist/esm/document-store/revoke-role.js +65 -0
  22. package/dist/esm/document-store/revoke.js +64 -0
  23. package/dist/esm/document-store/supportInterfaceIds.js +20 -0
  24. package/dist/esm/document-store/transferOwnership.js +40 -0
  25. package/dist/esm/document-store/tt-document-store-abi.js +229 -0
  26. package/dist/esm/document-store/types.js +1 -0
  27. package/dist/esm/index.js +1 -0
  28. package/dist/types/document-store/contract-interfaces.d.ts +14 -0
  29. package/dist/types/document-store/deploy.d.ts +29 -0
  30. package/dist/types/document-store/document-store-roles.d.ts +14 -0
  31. package/dist/types/document-store/grant-role.d.ts +28 -0
  32. package/dist/types/document-store/index.d.ts +15 -0
  33. package/dist/types/document-store/issue.d.ts +27 -0
  34. package/dist/types/document-store/revoke-role.d.ts +28 -0
  35. package/dist/types/document-store/revoke.d.ts +32 -0
  36. package/dist/types/document-store/supportInterfaceIds.d.ts +16 -0
  37. package/dist/types/document-store/transferOwnership.d.ts +30 -0
  38. package/dist/types/document-store/tt-document-store-abi.d.ts +388 -0
  39. package/dist/types/document-store/types.d.ts +15 -0
  40. package/dist/types/index.d.ts +17 -10
  41. package/package.json +2 -1
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ var revokeRole = require('./revoke-role');
4
+ var grantRole = require('./grant-role');
5
+ var documentStoreRoles = require('./document-store-roles');
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ const documentStoreTransferOwnership = /* @__PURE__ */ __name(async (documentStoreAddress, account, signer, options = {}) => {
10
+ if (!documentStoreAddress) throw new Error("Document store address is required");
11
+ if (!signer.provider) throw new Error("Provider is required");
12
+ if (!account) throw new Error("Account is required");
13
+ const ownerAddress = await signer.getAddress();
14
+ const roleString = await documentStoreRoles.getRoleString(documentStoreAddress, "admin", {
15
+ provider: signer.provider
16
+ });
17
+ const grantTransaction = grantRole.documentStoreGrantRole(
18
+ documentStoreAddress,
19
+ roleString,
20
+ account,
21
+ signer,
22
+ options
23
+ );
24
+ const grantTransactionResult = await grantTransaction;
25
+ if (!grantTransactionResult) {
26
+ throw new Error("Grant transaction failed, not proceeding with revoke transaction");
27
+ }
28
+ const revokeTransaction = revokeRole.documentStoreRevokeRole(
29
+ documentStoreAddress,
30
+ roleString,
31
+ ownerAddress,
32
+ signer,
33
+ options
34
+ );
35
+ const revokeTransactionResult = await revokeTransaction;
36
+ if (!revokeTransactionResult) {
37
+ throw new Error("Revoke transaction failed");
38
+ }
39
+ return { grantTransaction, revokeTransaction };
40
+ }, "documentStoreTransferOwnership");
41
+
42
+ exports.documentStoreTransferOwnership = documentStoreTransferOwnership;
@@ -0,0 +1,231 @@
1
+ 'use strict';
2
+
3
+ const TT_DOCUMENT_STORE_ABI = [
4
+ // TODO: Replace with the actual full ABI
5
+ // Minimal ABI for issue function (0x0f75e81f)
6
+ {
7
+ inputs: [
8
+ { internalType: "string", name: "_name", type: "string" },
9
+ { internalType: "address", name: "owner", type: "address" }
10
+ ],
11
+ stateMutability: "nonpayable",
12
+ type: "constructor"
13
+ },
14
+ {
15
+ anonymous: false,
16
+ inputs: [{ indexed: true, internalType: "bytes32", name: "document", type: "bytes32" }],
17
+ name: "DocumentIssued",
18
+ type: "event"
19
+ },
20
+ {
21
+ anonymous: false,
22
+ inputs: [{ indexed: true, internalType: "bytes32", name: "document", type: "bytes32" }],
23
+ name: "DocumentRevoked",
24
+ type: "event"
25
+ },
26
+ {
27
+ anonymous: false,
28
+ inputs: [
29
+ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
30
+ { indexed: true, internalType: "bytes32", name: "previousAdminRole", type: "bytes32" },
31
+ { indexed: true, internalType: "bytes32", name: "newAdminRole", type: "bytes32" }
32
+ ],
33
+ name: "RoleAdminChanged",
34
+ type: "event"
35
+ },
36
+ {
37
+ anonymous: false,
38
+ inputs: [
39
+ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
40
+ { indexed: true, internalType: "address", name: "account", type: "address" },
41
+ { indexed: true, internalType: "address", name: "sender", type: "address" }
42
+ ],
43
+ name: "RoleGranted",
44
+ type: "event"
45
+ },
46
+ {
47
+ anonymous: false,
48
+ inputs: [
49
+ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
50
+ { indexed: true, internalType: "address", name: "account", type: "address" },
51
+ { indexed: true, internalType: "address", name: "sender", type: "address" }
52
+ ],
53
+ name: "RoleRevoked",
54
+ type: "event"
55
+ },
56
+ {
57
+ inputs: [],
58
+ name: "DEFAULT_ADMIN_ROLE",
59
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
60
+ stateMutability: "view",
61
+ type: "function"
62
+ },
63
+ {
64
+ inputs: [],
65
+ name: "ISSUER_ROLE",
66
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
67
+ stateMutability: "view",
68
+ type: "function"
69
+ },
70
+ {
71
+ inputs: [],
72
+ name: "REVOKER_ROLE",
73
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
74
+ stateMutability: "view",
75
+ type: "function"
76
+ },
77
+ {
78
+ inputs: [{ internalType: "bytes32[]", name: "documents", type: "bytes32[]" }],
79
+ name: "bulkIssue",
80
+ outputs: [],
81
+ stateMutability: "nonpayable",
82
+ type: "function"
83
+ },
84
+ {
85
+ inputs: [{ internalType: "bytes32[]", name: "documents", type: "bytes32[]" }],
86
+ name: "bulkRevoke",
87
+ outputs: [],
88
+ stateMutability: "nonpayable",
89
+ type: "function"
90
+ },
91
+ {
92
+ inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
93
+ name: "documentIssued",
94
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
95
+ stateMutability: "view",
96
+ type: "function"
97
+ },
98
+ {
99
+ inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
100
+ name: "documentRevoked",
101
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
102
+ stateMutability: "view",
103
+ type: "function"
104
+ },
105
+ {
106
+ inputs: [{ internalType: "bytes32", name: "document", type: "bytes32" }],
107
+ name: "getIssuedBlock",
108
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
109
+ stateMutability: "view",
110
+ type: "function"
111
+ },
112
+ {
113
+ inputs: [{ internalType: "bytes32", name: "role", type: "bytes32" }],
114
+ name: "getRoleAdmin",
115
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
116
+ stateMutability: "view",
117
+ type: "function"
118
+ },
119
+ {
120
+ inputs: [
121
+ { internalType: "bytes32", name: "role", type: "bytes32" },
122
+ { internalType: "address", name: "account", type: "address" }
123
+ ],
124
+ name: "grantRole",
125
+ outputs: [],
126
+ stateMutability: "nonpayable",
127
+ type: "function"
128
+ },
129
+ {
130
+ inputs: [
131
+ { internalType: "bytes32", name: "role", type: "bytes32" },
132
+ { internalType: "address", name: "account", type: "address" }
133
+ ],
134
+ name: "hasRole",
135
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
136
+ stateMutability: "view",
137
+ type: "function"
138
+ },
139
+ {
140
+ inputs: [{ internalType: "bytes32", name: "document", type: "bytes32" }],
141
+ name: "isIssued",
142
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
143
+ stateMutability: "view",
144
+ type: "function"
145
+ },
146
+ {
147
+ inputs: [
148
+ { internalType: "bytes32", name: "document", type: "bytes32" },
149
+ { internalType: "uint256", name: "blockNumber", type: "uint256" }
150
+ ],
151
+ name: "isIssuedBefore",
152
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
153
+ stateMutability: "view",
154
+ type: "function"
155
+ },
156
+ {
157
+ inputs: [{ internalType: "bytes32", name: "document", type: "bytes32" }],
158
+ name: "isRevoked",
159
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
160
+ stateMutability: "view",
161
+ type: "function"
162
+ },
163
+ {
164
+ inputs: [
165
+ { internalType: "bytes32", name: "document", type: "bytes32" },
166
+ { internalType: "uint256", name: "blockNumber", type: "uint256" }
167
+ ],
168
+ name: "isRevokedBefore",
169
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
170
+ stateMutability: "view",
171
+ type: "function"
172
+ },
173
+ {
174
+ inputs: [{ internalType: "bytes32", name: "document", type: "bytes32" }],
175
+ name: "issue",
176
+ outputs: [],
177
+ stateMutability: "nonpayable",
178
+ type: "function"
179
+ },
180
+ {
181
+ inputs: [],
182
+ name: "name",
183
+ outputs: [{ internalType: "string", name: "", type: "string" }],
184
+ stateMutability: "view",
185
+ type: "function"
186
+ },
187
+ {
188
+ inputs: [
189
+ { internalType: "bytes32", name: "role", type: "bytes32" },
190
+ { internalType: "address", name: "account", type: "address" }
191
+ ],
192
+ name: "renounceRole",
193
+ outputs: [],
194
+ stateMutability: "nonpayable",
195
+ type: "function"
196
+ },
197
+ {
198
+ inputs: [{ internalType: "bytes32", name: "document", type: "bytes32" }],
199
+ name: "revoke",
200
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
201
+ stateMutability: "nonpayable",
202
+ type: "function"
203
+ },
204
+ {
205
+ inputs: [
206
+ { internalType: "bytes32", name: "role", type: "bytes32" },
207
+ { internalType: "address", name: "account", type: "address" }
208
+ ],
209
+ name: "revokeRole",
210
+ outputs: [],
211
+ stateMutability: "nonpayable",
212
+ type: "function"
213
+ },
214
+ {
215
+ inputs: [{ internalType: "bytes4", name: "interfaceId", type: "bytes4" }],
216
+ name: "supportsInterface",
217
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
218
+ stateMutability: "view",
219
+ type: "function"
220
+ },
221
+ {
222
+ inputs: [],
223
+ name: "version",
224
+ outputs: [{ internalType: "string", name: "", type: "string" }],
225
+ stateMutability: "view",
226
+ type: "function"
227
+ }
228
+ // Add other functions from the ABI here (name, isIssued, isRevoked, etc.)
229
+ ];
230
+
231
+ exports.TT_DOCUMENT_STORE_ABI = TT_DOCUMENT_STORE_ABI;
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
package/dist/cjs/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var tokenRegistryV4 = require('./token-registry-v4');
4
4
  var tokenRegistryV5 = require('./token-registry-v5');
5
+ var documentStore = require('./document-store');
5
6
  var tokenRegistryFunctions = require('./token-registry-functions');
6
7
  var core = require('./core');
7
8
  var openAttestation = require('./open-attestation');
@@ -81,6 +82,34 @@ Object.defineProperty(exports, "v5Utils", {
81
82
  enumerable: true,
82
83
  get: function () { return tokenRegistryV5.v5Utils; }
83
84
  });
85
+ Object.defineProperty(exports, "DocumentStore__factory", {
86
+ enumerable: true,
87
+ get: function () { return documentStore.DocumentStore__factory; }
88
+ });
89
+ Object.defineProperty(exports, "TransferableDocumentStore__factory", {
90
+ enumerable: true,
91
+ get: function () { return documentStore.TransferableDocumentStore__factory; }
92
+ });
93
+ Object.defineProperty(exports, "deployDocumentStore", {
94
+ enumerable: true,
95
+ get: function () { return documentStore.deployDocumentStore; }
96
+ });
97
+ Object.defineProperty(exports, "documentStoreGrantRole", {
98
+ enumerable: true,
99
+ get: function () { return documentStore.documentStoreGrantRole; }
100
+ });
101
+ Object.defineProperty(exports, "documentStoreIssue", {
102
+ enumerable: true,
103
+ get: function () { return documentStore.documentStoreIssue; }
104
+ });
105
+ Object.defineProperty(exports, "documentStoreRevoke", {
106
+ enumerable: true,
107
+ get: function () { return documentStore.documentStoreRevoke; }
108
+ });
109
+ Object.defineProperty(exports, "documentStoreRevokeRole", {
110
+ enumerable: true,
111
+ get: function () { return documentStore.documentStoreRevokeRole; }
112
+ });
84
113
  Object.keys(tokenRegistryFunctions).forEach(function (k) {
85
114
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
86
115
  enumerable: true,
@@ -0,0 +1,22 @@
1
+ import { IDocumentStore__factory, ITransferableDocumentStore__factory } from '@trustvc/document-store';
2
+
3
+ const IDocumentStoreInterface = IDocumentStore__factory.createInterface();
4
+ const ITransferableDocumentStoreInterface = ITransferableDocumentStore__factory.createInterface();
5
+ const IDocumentStoreFunctions = Object.values(IDocumentStoreInterface.fragments).filter((f) => f.type === "function").map((f) => f.format("sighash"));
6
+ const ITransferableDocumentStoreFunctions = Object.values(
7
+ ITransferableDocumentStoreInterface.fragments
8
+ ).filter((f) => f.type === "function").map((f) => f.format("sighash"));
9
+ const contractInterfaces = {
10
+ /**
11
+ * IDocumentStore interface functions
12
+ * Functions: isActive, isIssued, isRevoked, name, revoke
13
+ */
14
+ DocumentStore: IDocumentStoreFunctions,
15
+ /**
16
+ * ITransferableDocumentStore interface functions
17
+ * Functions: isActive, isIssued, isRevoked, issue, name, revoke
18
+ */
19
+ TransferableDocumentStore: ITransferableDocumentStoreFunctions
20
+ };
21
+
22
+ export { contractInterfaces };
@@ -0,0 +1,47 @@
1
+ import { TransferableDocumentStore__factory, DocumentStore__factory } from '@trustvc/document-store';
2
+ import { ContractFactory } from 'ethersV6';
3
+ import { ContractFactory as ContractFactory$1 } from 'ethers';
4
+ import { isV6EthersProvider } from '../utils/ethers';
5
+ import { getTxOptions } from '../token-registry-functions/utils';
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ const deployDocumentStore = /* @__PURE__ */ __name(async (storeName, owner, signer, options = {}) => {
10
+ if (!storeName) throw new Error("Store name is required");
11
+ if (!owner) throw new Error("Owner address is required");
12
+ if (!signer.provider) throw new Error("Provider is required");
13
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
14
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
15
+ const isV6 = isV6EthersProvider(signer.provider);
16
+ const DocumentStoreFactory = options.isTransferable ? TransferableDocumentStore__factory : DocumentStore__factory;
17
+ try {
18
+ if (isV6) {
19
+ const ContractFactory$1 = new ContractFactory(
20
+ DocumentStoreFactory.abi,
21
+ DocumentStoreFactory.bytecode,
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ signer
24
+ );
25
+ const contract = await ContractFactory$1.deploy(storeName, owner, txOptions);
26
+ const receipt = await contract.deploymentTransaction()?.wait();
27
+ return receipt;
28
+ } else {
29
+ const ContractFactory = new ContractFactory$1(
30
+ DocumentStoreFactory.abi,
31
+ DocumentStoreFactory.bytecode,
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ signer
34
+ );
35
+ const contract = await ContractFactory.deploy(storeName, owner, txOptions);
36
+ const receipt = await contract.deployTransaction.wait();
37
+ return receipt;
38
+ }
39
+ } catch (e) {
40
+ console.error("Deployment failed:", e);
41
+ throw new Error(
42
+ `Failed to deploy DocumentStore: ${e instanceof Error ? e.message : String(e)}`
43
+ );
44
+ }
45
+ }, "deployDocumentStore");
46
+
47
+ export { deployDocumentStore };
@@ -0,0 +1,35 @@
1
+ import { utils } from '@tradetrust-tt/tt-verify';
2
+ import { SUPPORTED_CHAINS } from '../utils';
3
+ import { getEthersContractFromProvider } from '../utils/ethers';
4
+ import { TT_DOCUMENT_STORE_ABI } from './tt-document-store-abi';
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ const getRoleString = /* @__PURE__ */ __name(async (documentStoreAddress, role, options) => {
9
+ const { chainId } = options || {};
10
+ let provider = options?.provider;
11
+ if (!provider) {
12
+ if (!chainId) throw new Error("Either provider or chainId must be provided");
13
+ provider = utils.getProvider({ network: SUPPORTED_CHAINS[chainId].name });
14
+ }
15
+ const Contract = getEthersContractFromProvider(provider);
16
+ const documentStore = new Contract(
17
+ documentStoreAddress,
18
+ TT_DOCUMENT_STORE_ABI,
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ provider
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");
31
+ }
32
+ }, "getRoleString");
33
+ const rolesList = ["admin", "issuer", "revoker"];
34
+
35
+ export { getRoleString, rolesList };
@@ -0,0 +1,65 @@
1
+ import { checkSupportsInterface } from '../core';
2
+ import { supportInterfaceIds } from './supportInterfaceIds';
3
+ import { TT_DOCUMENT_STORE_ABI } from './tt-document-store-abi';
4
+ import { getEthersContractFromProvider, isV6EthersProvider } from '../utils/ethers';
5
+ import { TransferableDocumentStore__factory, DocumentStore__factory } from '@trustvc/document-store';
6
+ import { getTxOptions } from '../token-registry-functions/utils';
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ const documentStoreGrantRole = /* @__PURE__ */ __name(async (documentStoreAddress, role, account, signer, options = {}) => {
11
+ if (!documentStoreAddress) throw new Error("Document store address is required");
12
+ if (!signer.provider) throw new Error("Provider is required");
13
+ if (!role) throw new Error("Role is required");
14
+ if (!account) throw new Error("Account is required");
15
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, isTransferable } = options;
16
+ let isDocumentStore = !isTransferable;
17
+ let isTransferableDocumentStore = isTransferable;
18
+ let isTTDocumentStore = false;
19
+ if (isTransferable === void 0) {
20
+ [isDocumentStore, isTransferableDocumentStore] = await Promise.all([
21
+ checkSupportsInterface(
22
+ documentStoreAddress,
23
+ supportInterfaceIds.IDocumentStore,
24
+ signer.provider
25
+ ),
26
+ checkSupportsInterface(
27
+ documentStoreAddress,
28
+ supportInterfaceIds.ITransferableDocumentStore,
29
+ signer.provider
30
+ )
31
+ ]);
32
+ if (!isDocumentStore && !isTransferableDocumentStore) {
33
+ isTTDocumentStore = true;
34
+ }
35
+ }
36
+ const Contract = getEthersContractFromProvider(signer.provider);
37
+ let documentStoreAbi;
38
+ if (isTTDocumentStore) {
39
+ documentStoreAbi = TT_DOCUMENT_STORE_ABI;
40
+ } else {
41
+ const DocumentStoreFactory = isTransferableDocumentStore ? TransferableDocumentStore__factory : DocumentStore__factory;
42
+ documentStoreAbi = DocumentStoreFactory.abi;
43
+ }
44
+ const documentStoreContract = new Contract(
45
+ documentStoreAddress,
46
+ documentStoreAbi,
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ signer
49
+ );
50
+ try {
51
+ const isV6 = isV6EthersProvider(signer.provider);
52
+ if (isV6) {
53
+ await documentStoreContract.grantRole.staticCall(role, account);
54
+ } else {
55
+ await documentStoreContract.callStatic.grantRole(role, account);
56
+ }
57
+ } catch (e) {
58
+ console.error("callStatic failed:", e);
59
+ throw new Error("Pre-check (callStatic) for grant-role failed");
60
+ }
61
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
62
+ return await documentStoreContract.grantRole(role, account, txOptions);
63
+ }, "documentStoreGrantRole");
64
+
65
+ export { documentStoreGrantRole };
@@ -0,0 +1,8 @@
1
+ export { documentStoreIssue } from './issue';
2
+ export { documentStoreRevoke } from './revoke';
3
+ export { documentStoreRevokeRole } from './revoke-role';
4
+ export { documentStoreGrantRole } from './grant-role';
5
+ export { documentStoreTransferOwnership } from './transferOwnership';
6
+ export { deployDocumentStore } from './deploy';
7
+ export { supportInterfaceIds } from './supportInterfaceIds';
8
+ export { DocumentStore__factory, TransferableDocumentStore__factory } from '@trustvc/document-store';
@@ -0,0 +1,64 @@
1
+ import { TransferableDocumentStore__factory, DocumentStore__factory } from '@trustvc/document-store';
2
+ import { getEthersContractFromProvider, isV6EthersProvider } from '../utils/ethers';
3
+ import { getTxOptions } from '../token-registry-functions/utils';
4
+ import { checkSupportsInterface } from '../core';
5
+ import { supportInterfaceIds } from './supportInterfaceIds';
6
+ import { TT_DOCUMENT_STORE_ABI } from './tt-document-store-abi';
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ const documentStoreIssue = /* @__PURE__ */ __name(async (documentStoreAddress, documentHash, signer, options = {}) => {
11
+ if (!documentStoreAddress) throw new Error("Document store address is required");
12
+ if (!signer.provider) throw new Error("Provider is required");
13
+ if (!documentHash) throw new Error("Document hash is required");
14
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, isTransferable } = options;
15
+ let isDocumentStore = !isTransferable;
16
+ let isTransferableDocumentStore = isTransferable;
17
+ let isTTDocumentStore = false;
18
+ if (isTransferable === void 0) {
19
+ [isDocumentStore, isTransferableDocumentStore] = await Promise.all([
20
+ checkSupportsInterface(
21
+ documentStoreAddress,
22
+ supportInterfaceIds.IDocumentStore,
23
+ signer.provider
24
+ ),
25
+ checkSupportsInterface(
26
+ documentStoreAddress,
27
+ supportInterfaceIds.ITransferableDocumentStore,
28
+ signer.provider
29
+ )
30
+ ]);
31
+ if (!isDocumentStore && !isTransferableDocumentStore) {
32
+ isTTDocumentStore = true;
33
+ }
34
+ }
35
+ const Contract = getEthersContractFromProvider(signer.provider);
36
+ let documentStoreAbi;
37
+ if (isTTDocumentStore) {
38
+ documentStoreAbi = TT_DOCUMENT_STORE_ABI;
39
+ } else {
40
+ const DocumentStoreFactory = isTransferableDocumentStore ? TransferableDocumentStore__factory : DocumentStore__factory;
41
+ documentStoreAbi = DocumentStoreFactory.abi;
42
+ }
43
+ const documentStoreContract = new Contract(
44
+ documentStoreAddress,
45
+ documentStoreAbi,
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ signer
48
+ );
49
+ try {
50
+ const isV6 = isV6EthersProvider(signer.provider);
51
+ if (isV6) {
52
+ await documentStoreContract.issue.staticCall(documentHash);
53
+ } else {
54
+ await documentStoreContract.callStatic.issue(documentHash);
55
+ }
56
+ } catch (e) {
57
+ console.error("callStatic failed:", e);
58
+ throw new Error("Pre-check (callStatic) for issue failed");
59
+ }
60
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
61
+ return await documentStoreContract.issue(documentHash, txOptions);
62
+ }, "documentStoreIssue");
63
+
64
+ export { documentStoreIssue };
@@ -0,0 +1,65 @@
1
+ import { checkSupportsInterface } from '../core';
2
+ import { supportInterfaceIds } from './supportInterfaceIds';
3
+ import { TT_DOCUMENT_STORE_ABI } from './tt-document-store-abi';
4
+ import { getEthersContractFromProvider, isV6EthersProvider } from '../utils/ethers';
5
+ import { TransferableDocumentStore__factory, DocumentStore__factory } from '@trustvc/document-store';
6
+ import { getTxOptions } from '../token-registry-functions/utils';
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ const documentStoreRevokeRole = /* @__PURE__ */ __name(async (documentStoreAddress, role, account, signer, options = {}) => {
11
+ if (!documentStoreAddress) throw new Error("Document store address is required");
12
+ if (!signer.provider) throw new Error("Provider is required");
13
+ if (!role) throw new Error("Role is required");
14
+ if (!account) throw new Error("Account is required");
15
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, isTransferable } = options;
16
+ let isDocumentStore = !isTransferable;
17
+ let isTransferableDocumentStore = isTransferable;
18
+ let isTTDocumentStore = false;
19
+ if (isTransferable === void 0) {
20
+ [isDocumentStore, isTransferableDocumentStore] = await Promise.all([
21
+ checkSupportsInterface(
22
+ documentStoreAddress,
23
+ supportInterfaceIds.IDocumentStore,
24
+ signer.provider
25
+ ),
26
+ checkSupportsInterface(
27
+ documentStoreAddress,
28
+ supportInterfaceIds.ITransferableDocumentStore,
29
+ signer.provider
30
+ )
31
+ ]);
32
+ if (!isDocumentStore && !isTransferableDocumentStore) {
33
+ isTTDocumentStore = true;
34
+ }
35
+ }
36
+ const Contract = getEthersContractFromProvider(signer.provider);
37
+ let documentStoreAbi;
38
+ if (isTTDocumentStore) {
39
+ documentStoreAbi = TT_DOCUMENT_STORE_ABI;
40
+ } else {
41
+ const DocumentStoreFactory = isTransferableDocumentStore ? TransferableDocumentStore__factory : DocumentStore__factory;
42
+ documentStoreAbi = DocumentStoreFactory.abi;
43
+ }
44
+ const documentStoreContract = new Contract(
45
+ documentStoreAddress,
46
+ documentStoreAbi,
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ signer
49
+ );
50
+ try {
51
+ const isV6 = isV6EthersProvider(signer.provider);
52
+ if (isV6) {
53
+ await documentStoreContract.revokeRole.staticCall(role, account);
54
+ } else {
55
+ await documentStoreContract.callStatic.revokeRole(role, account);
56
+ }
57
+ } catch (e) {
58
+ console.error("callStatic failed:", e);
59
+ throw new Error("Pre-check (callStatic) for revoke-role failed");
60
+ }
61
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
62
+ return await documentStoreContract.revokeRole(role, account, txOptions);
63
+ }, "documentStoreRevokeRole");
64
+
65
+ export { documentStoreRevokeRole };