@trustvc/trustvc 2.7.0 → 2.9.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 (47) hide show
  1. package/dist/cjs/{document-store/deploy.js → deploy/document-store.js} +18 -18
  2. package/dist/cjs/deploy/token-registry.js +97 -0
  3. package/dist/cjs/document-store/grant-role.js +67 -0
  4. package/dist/cjs/document-store/index.js +15 -12
  5. package/dist/cjs/document-store/issue.js +0 -5
  6. package/dist/cjs/document-store/revoke-role.js +67 -0
  7. package/dist/cjs/document-store/revoke.js +0 -5
  8. package/dist/cjs/document-store/transferOwnership.js +42 -0
  9. package/dist/cjs/document-store/types.js +2 -0
  10. package/dist/cjs/index.js +8 -0
  11. package/dist/cjs/token-registry-functions/index.js +7 -0
  12. package/dist/cjs/token-registry-functions/ownerOf.js +9 -7
  13. package/dist/cjs/token-registry-functions/utils.js +39 -0
  14. package/dist/cjs/token-registry-v5/index.js +4 -4
  15. package/dist/cjs/utils/ethers/index.js +6 -2
  16. package/dist/esm/{document-store/deploy.js → deploy/document-store.js} +19 -19
  17. package/dist/esm/deploy/token-registry.js +95 -0
  18. package/dist/esm/document-store/grant-role.js +65 -0
  19. package/dist/esm/document-store/index.js +6 -3
  20. package/dist/esm/document-store/issue.js +0 -5
  21. package/dist/esm/document-store/revoke-role.js +65 -0
  22. package/dist/esm/document-store/revoke.js +0 -5
  23. package/dist/esm/document-store/transferOwnership.js +40 -0
  24. package/dist/esm/document-store/types.js +1 -0
  25. package/dist/esm/index.js +1 -1
  26. package/dist/esm/token-registry-functions/index.js +1 -0
  27. package/dist/esm/token-registry-functions/ownerOf.js +9 -7
  28. package/dist/esm/token-registry-functions/utils.js +38 -2
  29. package/dist/esm/token-registry-v5/index.js +1 -1
  30. package/dist/esm/utils/ethers/index.js +7 -4
  31. package/dist/types/deploy/document-store.d.ts +77 -0
  32. package/dist/types/deploy/token-registry.d.ts +82 -0
  33. package/dist/types/document-store/grant-role.d.ts +28 -0
  34. package/dist/types/document-store/index.d.ts +7 -3
  35. package/dist/types/document-store/issue.d.ts +6 -11
  36. package/dist/types/document-store/revoke-role.d.ts +28 -0
  37. package/dist/types/document-store/transferOwnership.d.ts +30 -0
  38. package/dist/types/document-store/types.d.ts +15 -0
  39. package/dist/types/index.d.ts +17 -13
  40. package/dist/types/token-registry-functions/index.d.ts +1 -0
  41. package/dist/types/token-registry-functions/ownerOf.d.ts +1 -1
  42. package/dist/types/token-registry-functions/types.d.ts +26 -1
  43. package/dist/types/token-registry-functions/utils.d.ts +7 -4
  44. package/dist/types/token-registry-v5/index.d.ts +1 -2
  45. package/dist/types/utils/ethers/index.d.ts +6 -5
  46. package/package.json +1 -1
  47. package/dist/types/document-store/deploy.d.ts +0 -29
@@ -1,8 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var documentStore = require('@trustvc/document-store');
4
- var ethersV6 = require('ethersV6');
5
- var ethers$1 = require('ethers');
6
4
  var ethers = require('../utils/ethers');
7
5
  var utils = require('../token-registry-functions/utils');
8
6
 
@@ -16,27 +14,29 @@ const deployDocumentStore = /* @__PURE__ */ __name(async (storeName, owner, sign
16
14
  const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
17
15
  const isV6 = ethers.isV6EthersProvider(signer.provider);
18
16
  const DocumentStoreFactory = options.isTransferable ? documentStore.TransferableDocumentStore__factory : documentStore.DocumentStore__factory;
17
+ const ContractFactory = ethers.getEthersContractFactoryFromProvider(signer.provider);
18
+ const contractFactory = new ContractFactory(
19
+ DocumentStoreFactory.abi,
20
+ DocumentStoreFactory.bytecode,
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+ signer
23
+ // Type assertion needed for v5/v6 compatibility
24
+ );
19
25
  try {
20
26
  if (isV6) {
21
- const ContractFactory = new ethersV6.ContractFactory(
22
- DocumentStoreFactory.abi,
23
- DocumentStoreFactory.bytecode,
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- signer
27
+ const contract = await contractFactory.deploy(
28
+ storeName,
29
+ owner,
30
+ txOptions
26
31
  );
27
- const contract = await ContractFactory.deploy(storeName, owner, txOptions);
28
- const receipt = await contract.deploymentTransaction()?.wait();
29
- return receipt;
32
+ return await contract.deploymentTransaction().wait();
30
33
  } else {
31
- const ContractFactory = new ethers$1.ContractFactory(
32
- DocumentStoreFactory.abi,
33
- DocumentStoreFactory.bytecode,
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- signer
34
+ const contract = await contractFactory.deploy(
35
+ storeName,
36
+ owner,
37
+ txOptions
36
38
  );
37
- const contract = await ContractFactory.deploy(storeName, owner, txOptions);
38
- const receipt = await contract.deployTransaction.wait();
39
- return receipt;
39
+ return await contract.deployTransaction.wait();
40
40
  }
41
41
  } catch (e) {
42
42
  console.error("Deployment failed:", e);
@@ -0,0 +1,97 @@
1
+ 'use strict';
2
+
3
+ var contracts = require('@tradetrust-tt/token-registry/contracts');
4
+ var utils = require('../token-registry-functions/utils');
5
+ var utils$1 = require('../token-registry-v5/utils');
6
+ var ethers = require('../utils/ethers');
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ const deployTokenRegistry = /* @__PURE__ */ __name(async (registryName, registrySymbol, signer, options = {}) => {
11
+ const { maxFeePerGas, maxPriorityFeePerGas } = options;
12
+ let { chainId, standalone, factoryAddress, tokenRegistryImplAddress, deployerContractAddress } = options;
13
+ const deployerAddress = await signer.getAddress();
14
+ if (!chainId) {
15
+ chainId = await utils.getChainIdSafe(signer);
16
+ }
17
+ const {
18
+ TitleEscrowFactory: defaultTitleEscrowFactoryAddress,
19
+ TokenImplementation: defaultTokenImplementationContractAddress,
20
+ Deployer: defaultDeployerContractAddress
21
+ } = utils.getDefaultContractAddress(chainId);
22
+ if (!utils.isValidAddress(deployerContractAddress)) {
23
+ deployerContractAddress = defaultDeployerContractAddress;
24
+ }
25
+ if (!utils.isValidAddress(tokenRegistryImplAddress)) {
26
+ tokenRegistryImplAddress = defaultTokenImplementationContractAddress;
27
+ }
28
+ if (standalone !== false && (!deployerContractAddress || !tokenRegistryImplAddress)) {
29
+ console.error(
30
+ `Network ${chainId} does not support "quick-start" mode. Defaulting to standalone mode.`
31
+ );
32
+ standalone = true;
33
+ }
34
+ if (!standalone) {
35
+ if (!deployerContractAddress || !tokenRegistryImplAddress) {
36
+ throw new Error(`Network ${chainId} currently is not supported. Use --standalone instead.`);
37
+ }
38
+ const Contract = ethers.getEthersContractFromProvider(signer.provider);
39
+ const deployerContract = new Contract(
40
+ deployerContractAddress,
41
+ contracts.TDocDeployer__factory.abi,
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ signer
44
+ // Type assertion needed for v5/v6 compatibility
45
+ );
46
+ const initParam = utils$1.encodeInitParams({
47
+ name: registryName,
48
+ symbol: registrySymbol,
49
+ deployer: deployerAddress
50
+ });
51
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
52
+ return await deployerContract.deploy(tokenRegistryImplAddress, initParam, txOptions);
53
+ } else {
54
+ if (!factoryAddress || !utils.isValidAddress(factoryAddress)) {
55
+ factoryAddress = defaultTitleEscrowFactoryAddress;
56
+ if (!factoryAddress) {
57
+ throw new Error(`Network ${chainId} currently is not supported. Supply a factory address.`);
58
+ }
59
+ }
60
+ const supportedTitleEscrowFactory = await utils.isSupportedTitleEscrowFactory(
61
+ factoryAddress,
62
+ signer.provider
63
+ );
64
+ if (!supportedTitleEscrowFactory) {
65
+ throw new Error(`Title Escrow Factory ${factoryAddress} is not supported.`);
66
+ }
67
+ const Contract = ethers.getEthersContractFactoryFromProvider(signer.provider);
68
+ const tokenFactory = new Contract(
69
+ contracts.TradeTrustToken__factory.abi,
70
+ contracts.TradeTrustToken__factory.bytecode,
71
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
+ signer
73
+ // Type assertion needed for v5/v6 compatibility
74
+ );
75
+ const isV6 = ethers.isV6EthersProvider(signer.provider);
76
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
77
+ if (isV6) {
78
+ const contract = await tokenFactory.deploy(
79
+ registryName,
80
+ registrySymbol,
81
+ factoryAddress,
82
+ txOptions
83
+ );
84
+ return await contract.deploymentTransaction().wait();
85
+ } else {
86
+ const contract = await tokenFactory.deploy(
87
+ registryName,
88
+ registrySymbol,
89
+ factoryAddress,
90
+ txOptions
91
+ );
92
+ return await contract.deployTransaction.wait();
93
+ }
94
+ }
95
+ }, "deployTokenRegistry");
96
+
97
+ exports.deployTokenRegistry = deployTokenRegistry;
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ var core = require('../core');
4
+ var supportInterfaceIds = require('./supportInterfaceIds');
5
+ var ttDocumentStoreAbi = require('./tt-document-store-abi');
6
+ var ethers = require('../utils/ethers');
7
+ var documentStore = require('@trustvc/document-store');
8
+ var utils = require('../token-registry-functions/utils');
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
+ const documentStoreGrantRole = /* @__PURE__ */ __name(async (documentStoreAddress, role, account, signer, options = {}) => {
13
+ if (!documentStoreAddress) throw new Error("Document store address is required");
14
+ if (!signer.provider) throw new Error("Provider is required");
15
+ if (!role) throw new Error("Role is required");
16
+ if (!account) throw new Error("Account is required");
17
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, isTransferable } = options;
18
+ let isDocumentStore = !isTransferable;
19
+ let isTransferableDocumentStore = isTransferable;
20
+ let isTTDocumentStore = false;
21
+ if (isTransferable === void 0) {
22
+ [isDocumentStore, isTransferableDocumentStore] = await Promise.all([
23
+ core.checkSupportsInterface(
24
+ documentStoreAddress,
25
+ supportInterfaceIds.supportInterfaceIds.IDocumentStore,
26
+ signer.provider
27
+ ),
28
+ core.checkSupportsInterface(
29
+ documentStoreAddress,
30
+ supportInterfaceIds.supportInterfaceIds.ITransferableDocumentStore,
31
+ signer.provider
32
+ )
33
+ ]);
34
+ if (!isDocumentStore && !isTransferableDocumentStore) {
35
+ isTTDocumentStore = true;
36
+ }
37
+ }
38
+ const Contract = ethers.getEthersContractFromProvider(signer.provider);
39
+ let documentStoreAbi;
40
+ if (isTTDocumentStore) {
41
+ documentStoreAbi = ttDocumentStoreAbi.TT_DOCUMENT_STORE_ABI;
42
+ } else {
43
+ const DocumentStoreFactory = isTransferableDocumentStore ? documentStore.TransferableDocumentStore__factory : documentStore.DocumentStore__factory;
44
+ documentStoreAbi = DocumentStoreFactory.abi;
45
+ }
46
+ const documentStoreContract = new Contract(
47
+ documentStoreAddress,
48
+ documentStoreAbi,
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ signer
51
+ );
52
+ try {
53
+ const isV6 = ethers.isV6EthersProvider(signer.provider);
54
+ if (isV6) {
55
+ await documentStoreContract.grantRole.staticCall(role, account);
56
+ } else {
57
+ await documentStoreContract.callStatic.grantRole(role, account);
58
+ }
59
+ } catch (e) {
60
+ console.error("callStatic failed:", e);
61
+ throw new Error("Pre-check (callStatic) for grant-role failed");
62
+ }
63
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
64
+ return await documentStoreContract.grantRole(role, account, txOptions);
65
+ }, "documentStoreGrantRole");
66
+
67
+ exports.documentStoreGrantRole = documentStoreGrantRole;
@@ -2,35 +2,38 @@
2
2
 
3
3
  var issue = require('./issue');
4
4
  var revoke = require('./revoke');
5
- var deploy = require('./deploy');
5
+ var revokeRole = require('./revoke-role');
6
+ var grantRole = require('./grant-role');
7
+ var transferOwnership = require('./transferOwnership');
8
+ var documentStore$1 = require('../deploy/document-store');
6
9
  var supportInterfaceIds = require('./supportInterfaceIds');
7
10
  var documentStore = require('@trustvc/document-store');
8
11
 
9
12
 
10
13
 
11
- Object.defineProperty(exports, "IssueOptions", {
12
- enumerable: true,
13
- get: function () { return issue.IssueOptions; }
14
- });
15
14
  Object.defineProperty(exports, "documentStoreIssue", {
16
15
  enumerable: true,
17
16
  get: function () { return issue.documentStoreIssue; }
18
17
  });
19
- Object.defineProperty(exports, "RevokeOptions", {
20
- enumerable: true,
21
- get: function () { return revoke.RevokeOptions; }
22
- });
23
18
  Object.defineProperty(exports, "documentStoreRevoke", {
24
19
  enumerable: true,
25
20
  get: function () { return revoke.documentStoreRevoke; }
26
21
  });
27
- Object.defineProperty(exports, "DeployOptions", {
22
+ Object.defineProperty(exports, "documentStoreRevokeRole", {
23
+ enumerable: true,
24
+ get: function () { return revokeRole.documentStoreRevokeRole; }
25
+ });
26
+ Object.defineProperty(exports, "documentStoreGrantRole", {
27
+ enumerable: true,
28
+ get: function () { return grantRole.documentStoreGrantRole; }
29
+ });
30
+ Object.defineProperty(exports, "documentStoreTransferOwnership", {
28
31
  enumerable: true,
29
- get: function () { return deploy.DeployOptions; }
32
+ get: function () { return transferOwnership.documentStoreTransferOwnership; }
30
33
  });
31
34
  Object.defineProperty(exports, "deployDocumentStore", {
32
35
  enumerable: true,
33
- get: function () { return deploy.deployDocumentStore; }
36
+ get: function () { return documentStore$1.deployDocumentStore; }
34
37
  });
35
38
  Object.defineProperty(exports, "supportInterfaceIds", {
36
39
  enumerable: true,
@@ -34,11 +34,6 @@ const documentStoreIssue = /* @__PURE__ */ __name(async (documentStoreAddress, d
34
34
  isTTDocumentStore = true;
35
35
  }
36
36
  }
37
- if (!isDocumentStore && !isTransferableDocumentStore && !isTTDocumentStore) {
38
- throw new Error(
39
- "Contract does not support DocumentStore, TransferableDocumentStore, or TT Document Store interface"
40
- );
41
- }
42
37
  const Contract = ethers.getEthersContractFromProvider(signer.provider);
43
38
  let documentStoreAbi;
44
39
  if (isTTDocumentStore) {
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ var core = require('../core');
4
+ var supportInterfaceIds = require('./supportInterfaceIds');
5
+ var ttDocumentStoreAbi = require('./tt-document-store-abi');
6
+ var ethers = require('../utils/ethers');
7
+ var documentStore = require('@trustvc/document-store');
8
+ var utils = require('../token-registry-functions/utils');
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
+ const documentStoreRevokeRole = /* @__PURE__ */ __name(async (documentStoreAddress, role, account, signer, options = {}) => {
13
+ if (!documentStoreAddress) throw new Error("Document store address is required");
14
+ if (!signer.provider) throw new Error("Provider is required");
15
+ if (!role) throw new Error("Role is required");
16
+ if (!account) throw new Error("Account is required");
17
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, isTransferable } = options;
18
+ let isDocumentStore = !isTransferable;
19
+ let isTransferableDocumentStore = isTransferable;
20
+ let isTTDocumentStore = false;
21
+ if (isTransferable === void 0) {
22
+ [isDocumentStore, isTransferableDocumentStore] = await Promise.all([
23
+ core.checkSupportsInterface(
24
+ documentStoreAddress,
25
+ supportInterfaceIds.supportInterfaceIds.IDocumentStore,
26
+ signer.provider
27
+ ),
28
+ core.checkSupportsInterface(
29
+ documentStoreAddress,
30
+ supportInterfaceIds.supportInterfaceIds.ITransferableDocumentStore,
31
+ signer.provider
32
+ )
33
+ ]);
34
+ if (!isDocumentStore && !isTransferableDocumentStore) {
35
+ isTTDocumentStore = true;
36
+ }
37
+ }
38
+ const Contract = ethers.getEthersContractFromProvider(signer.provider);
39
+ let documentStoreAbi;
40
+ if (isTTDocumentStore) {
41
+ documentStoreAbi = ttDocumentStoreAbi.TT_DOCUMENT_STORE_ABI;
42
+ } else {
43
+ const DocumentStoreFactory = isTransferableDocumentStore ? documentStore.TransferableDocumentStore__factory : documentStore.DocumentStore__factory;
44
+ documentStoreAbi = DocumentStoreFactory.abi;
45
+ }
46
+ const documentStoreContract = new Contract(
47
+ documentStoreAddress,
48
+ documentStoreAbi,
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ signer
51
+ );
52
+ try {
53
+ const isV6 = ethers.isV6EthersProvider(signer.provider);
54
+ if (isV6) {
55
+ await documentStoreContract.revokeRole.staticCall(role, account);
56
+ } else {
57
+ await documentStoreContract.callStatic.revokeRole(role, account);
58
+ }
59
+ } catch (e) {
60
+ console.error("callStatic failed:", e);
61
+ throw new Error("Pre-check (callStatic) for revoke-role failed");
62
+ }
63
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
64
+ return await documentStoreContract.revokeRole(role, account, txOptions);
65
+ }, "documentStoreRevokeRole");
66
+
67
+ exports.documentStoreRevokeRole = documentStoreRevokeRole;
@@ -34,11 +34,6 @@ const documentStoreRevoke = /* @__PURE__ */ __name(async (documentStoreAddress,
34
34
  isTTDocumentStore = true;
35
35
  }
36
36
  }
37
- if (!isDocumentStore && !isTransferableDocumentStore && !isTTDocumentStore) {
38
- throw new Error(
39
- "Contract does not support DocumentStore, TransferableDocumentStore, or TT Document Store interface"
40
- );
41
- }
42
37
  const Contract = ethers.getEthersContractFromProvider(signer.provider);
43
38
  let documentStoreAbi;
44
39
  if (isTTDocumentStore) {
@@ -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,2 @@
1
+ 'use strict';
2
+
package/dist/cjs/index.js CHANGED
@@ -94,6 +94,10 @@ Object.defineProperty(exports, "deployDocumentStore", {
94
94
  enumerable: true,
95
95
  get: function () { return documentStore.deployDocumentStore; }
96
96
  });
97
+ Object.defineProperty(exports, "documentStoreGrantRole", {
98
+ enumerable: true,
99
+ get: function () { return documentStore.documentStoreGrantRole; }
100
+ });
97
101
  Object.defineProperty(exports, "documentStoreIssue", {
98
102
  enumerable: true,
99
103
  get: function () { return documentStore.documentStoreIssue; }
@@ -102,6 +106,10 @@ Object.defineProperty(exports, "documentStoreRevoke", {
102
106
  enumerable: true,
103
107
  get: function () { return documentStore.documentStoreRevoke; }
104
108
  });
109
+ Object.defineProperty(exports, "documentStoreRevokeRole", {
110
+ enumerable: true,
111
+ get: function () { return documentStore.documentStoreRevokeRole; }
112
+ });
105
113
  Object.keys(tokenRegistryFunctions).forEach(function (k) {
106
114
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
107
115
  enumerable: true,
@@ -5,6 +5,7 @@ var rejectTransfers = require('./rejectTransfers');
5
5
  var returnToken = require('./returnToken');
6
6
  var mint = require('./mint');
7
7
  var ownerOf = require('./ownerOf');
8
+ var tokenRegistry = require('../deploy/token-registry');
8
9
 
9
10
 
10
11
 
@@ -38,3 +39,9 @@ Object.keys(ownerOf).forEach(function (k) {
38
39
  get: function () { return ownerOf[k]; }
39
40
  });
40
41
  });
42
+ Object.keys(tokenRegistry).forEach(function (k) {
43
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
44
+ enumerable: true,
45
+ get: function () { return tokenRegistry[k]; }
46
+ });
47
+ });
@@ -3,6 +3,7 @@
3
3
  var core = require('../core');
4
4
  var tokenRegistryV5 = require('../token-registry-v5');
5
5
  var tokenRegistryV4 = require('../token-registry-v4');
6
+ var ethers = require('../utils/ethers');
6
7
 
7
8
  var __defProp = Object.defineProperty;
8
9
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -23,23 +24,24 @@ const ownerOf = /* @__PURE__ */ __name(async (contractOptions, signer, params, o
23
24
  if (!isV4TT && !isV5TT) {
24
25
  throw new Error("Only Token Registry V4/V5 is supported");
25
26
  }
27
+ const Contract = ethers.getEthersContractFromProvider(signer.provider);
26
28
  let tradeTrustTokenContract;
27
29
  if (isV5TT) {
28
- tradeTrustTokenContract = tokenRegistryV5.v5Contracts.TradeTrustToken__factory.connect(
30
+ tradeTrustTokenContract = new Contract(
29
31
  tokenRegistryAddress,
32
+ tokenRegistryV5.v5Contracts.TradeTrustToken__factory.abi,
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
34
  signer
31
35
  );
32
36
  } else if (isV4TT) {
33
- tradeTrustTokenContract = tokenRegistryV4.v4Contracts.TradeTrustToken__factory.connect(
37
+ tradeTrustTokenContract = new Contract(
34
38
  tokenRegistryAddress,
39
+ tokenRegistryV4.v4Contracts.TradeTrustToken__factory.abi,
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
41
  signer
36
42
  );
37
43
  }
38
- if (isV5TT) {
39
- return await tradeTrustTokenContract.ownerOf(tokenId);
40
- } else if (isV4TT) {
41
- return await tradeTrustTokenContract.ownerOf(tokenId);
42
- }
44
+ return await tradeTrustTokenContract.ownerOf(tokenId);
43
45
  }, "ownerOf");
44
46
 
45
47
  exports.ownerOf = ownerOf;
@@ -2,6 +2,8 @@
2
2
 
3
3
  var ethers = require('../utils/ethers');
4
4
  var utils = require('../utils');
5
+ var ethersV6 = require('ethersV6');
6
+ var tokenRegistryV5 = require('../token-registry-v5');
5
7
 
6
8
  var __defProp = Object.defineProperty;
7
9
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -31,7 +33,44 @@ const getSignerAddressSafe = /* @__PURE__ */ __name(async (signer) => {
31
33
  }
32
34
  return await signer.getAddress();
33
35
  }, "getSignerAddressSafe");
36
+ const { contractInterfaceId: CONTRACT_INTERFACE_ID, contractAddress: CONTRACT_ADDRESS } = tokenRegistryV5.constants;
37
+ const getDefaultContractAddress = /* @__PURE__ */ __name((chainId) => {
38
+ const { TitleEscrowFactory, TokenImplementation, Deployer } = CONTRACT_ADDRESS;
39
+ const chainTitleEscrowFactory = TitleEscrowFactory[chainId];
40
+ const chainTokenImplementation = TokenImplementation[chainId];
41
+ const chainDeployer = Deployer[chainId];
42
+ return {
43
+ TitleEscrowFactory: chainTitleEscrowFactory,
44
+ TokenImplementation: chainTokenImplementation,
45
+ Deployer: chainDeployer
46
+ };
47
+ }, "getDefaultContractAddress");
48
+ const isValidAddress = /* @__PURE__ */ __name((address) => {
49
+ if (!address) return false;
50
+ return ethersV6.isAddress(address);
51
+ }, "isValidAddress");
52
+ const isSupportedTitleEscrowFactory = /* @__PURE__ */ __name(async (factoryAddress, provider) => {
53
+ const Contract = ethers.getEthersContractFromProvider(provider);
54
+ const titleEscrowFactoryContract = new Contract(
55
+ factoryAddress,
56
+ ["function implementation() view returns (address)"],
57
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
+ provider
59
+ );
60
+ const implAddr = await titleEscrowFactoryContract.implementation();
61
+ const implContract = new Contract(
62
+ implAddr,
63
+ ["function supportsInterface(bytes4 interfaceId) view returns (bool)"],
64
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
+ provider
66
+ );
67
+ const { TitleEscrow: titleEscrowInterfaceId } = CONTRACT_INTERFACE_ID;
68
+ return implContract.supportsInterface(titleEscrowInterfaceId);
69
+ }, "isSupportedTitleEscrowFactory");
34
70
 
35
71
  exports.getChainIdSafe = getChainIdSafe;
72
+ exports.getDefaultContractAddress = getDefaultContractAddress;
36
73
  exports.getSignerAddressSafe = getSignerAddressSafe;
37
74
  exports.getTxOptions = getTxOptions;
75
+ exports.isSupportedTitleEscrowFactory = isSupportedTitleEscrowFactory;
76
+ exports.isValidAddress = isValidAddress;
@@ -5,7 +5,7 @@ var roleHash = require('./roleHash');
5
5
  var supportInterfaceIds = require('./supportInterfaceIds');
6
6
  var contracts = require('./contracts');
7
7
  var utils = require('./utils');
8
- var tokenRegistryV4 = require('@tradetrust-tt/token-registry-v4');
8
+ var tokenRegistryV5 = require('@tradetrust-tt/token-registry-v5');
9
9
 
10
10
  function _interopNamespace(e) {
11
11
  if (e && e.__esModule) return e;
@@ -56,13 +56,13 @@ Object.defineProperty(exports, "v5GetEventFromReceipt", {
56
56
  });
57
57
  Object.defineProperty(exports, "constants", {
58
58
  enumerable: true,
59
- get: function () { return tokenRegistryV4.constants; }
59
+ get: function () { return tokenRegistryV5.constants; }
60
60
  });
61
61
  Object.defineProperty(exports, "utils", {
62
62
  enumerable: true,
63
- get: function () { return tokenRegistryV4.utils; }
63
+ get: function () { return tokenRegistryV5.utils; }
64
64
  });
65
65
  Object.defineProperty(exports, "v5Utils", {
66
66
  enumerable: true,
67
- get: function () { return tokenRegistryV4.utils; }
67
+ get: function () { return tokenRegistryV5.utils; }
68
68
  });
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var ethers = require('ethers');
4
3
  var ethersV6 = require('ethersV6');
4
+ var ethers = require('ethers');
5
5
 
6
6
  var __defProp = Object.defineProperty;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -16,8 +16,12 @@ const isV6EthersProvider = /* @__PURE__ */ __name((provider) => {
16
16
  throw new Error("Unknown provider type");
17
17
  }, "isV6EthersProvider");
18
18
  const getEthersContractFromProvider = /* @__PURE__ */ __name((provider) => {
19
- return isV6EthersProvider(provider) ? ethersV6.ethers.Contract : ethers.ethers.Contract;
19
+ return isV6EthersProvider(provider) ? ethersV6.Contract : ethers.Contract;
20
20
  }, "getEthersContractFromProvider");
21
+ const getEthersContractFactoryFromProvider = /* @__PURE__ */ __name((provider) => {
22
+ return isV6EthersProvider(provider) ? ethersV6.ContractFactory : ethers.ContractFactory;
23
+ }, "getEthersContractFactoryFromProvider");
21
24
 
25
+ exports.getEthersContractFactoryFromProvider = getEthersContractFactoryFromProvider;
22
26
  exports.getEthersContractFromProvider = getEthersContractFromProvider;
23
27
  exports.isV6EthersProvider = isV6EthersProvider;
@@ -1,7 +1,5 @@
1
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';
2
+ import { isV6EthersProvider, getEthersContractFactoryFromProvider } from '../utils/ethers';
5
3
  import { getTxOptions } from '../token-registry-functions/utils';
6
4
 
7
5
  var __defProp = Object.defineProperty;
@@ -14,27 +12,29 @@ const deployDocumentStore = /* @__PURE__ */ __name(async (storeName, owner, sign
14
12
  const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
15
13
  const isV6 = isV6EthersProvider(signer.provider);
16
14
  const DocumentStoreFactory = options.isTransferable ? TransferableDocumentStore__factory : DocumentStore__factory;
15
+ const ContractFactory = getEthersContractFactoryFromProvider(signer.provider);
16
+ const contractFactory = new ContractFactory(
17
+ DocumentStoreFactory.abi,
18
+ DocumentStoreFactory.bytecode,
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ signer
21
+ // Type assertion needed for v5/v6 compatibility
22
+ );
17
23
  try {
18
24
  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
25
+ const contract = await contractFactory.deploy(
26
+ storeName,
27
+ owner,
28
+ txOptions
24
29
  );
25
- const contract = await ContractFactory$1.deploy(storeName, owner, txOptions);
26
- const receipt = await contract.deploymentTransaction()?.wait();
27
- return receipt;
30
+ return await contract.deploymentTransaction().wait();
28
31
  } 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
32
+ const contract = await contractFactory.deploy(
33
+ storeName,
34
+ owner,
35
+ txOptions
34
36
  );
35
- const contract = await ContractFactory.deploy(storeName, owner, txOptions);
36
- const receipt = await contract.deployTransaction.wait();
37
- return receipt;
37
+ return await contract.deployTransaction.wait();
38
38
  }
39
39
  } catch (e) {
40
40
  console.error("Deployment failed:", e);