@trustvc/trustvc 1.5.5 → 1.6.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/cjs/core/endorsement-chain/useEndorsementChain.js +5 -6
  2. package/dist/cjs/index.js +7 -0
  3. package/dist/cjs/token-registry-functions/index.js +40 -0
  4. package/dist/cjs/token-registry-functions/mint.js +86 -0
  5. package/dist/cjs/token-registry-functions/ownerOf.js +45 -0
  6. package/dist/cjs/token-registry-functions/rejectTransfers.js +123 -0
  7. package/dist/cjs/token-registry-functions/returnToken.js +204 -0
  8. package/dist/cjs/token-registry-functions/transfer.js +305 -0
  9. package/dist/cjs/token-registry-functions/types.js +2 -0
  10. package/dist/cjs/token-registry-functions/utils.js +37 -0
  11. package/dist/esm/core/endorsement-chain/useEndorsementChain.js +5 -7
  12. package/dist/esm/index.js +1 -0
  13. package/dist/esm/token-registry-functions/index.js +5 -0
  14. package/dist/esm/token-registry-functions/mint.js +84 -0
  15. package/dist/esm/token-registry-functions/ownerOf.js +43 -0
  16. package/dist/esm/token-registry-functions/rejectTransfers.js +119 -0
  17. package/dist/esm/token-registry-functions/returnToken.js +200 -0
  18. package/dist/esm/token-registry-functions/transfer.js +300 -0
  19. package/dist/esm/token-registry-functions/types.js +1 -0
  20. package/dist/esm/token-registry-functions/utils.js +33 -0
  21. package/dist/types/core/endorsement-chain/index.d.ts +1 -1
  22. package/dist/types/core/endorsement-chain/useEndorsementChain.d.ts +2 -1
  23. package/dist/types/core/index.d.ts +1 -1
  24. package/dist/types/index.d.ts +7 -1
  25. package/dist/types/token-registry-functions/index.d.ts +9 -0
  26. package/dist/types/token-registry-functions/mint.d.ts +20 -0
  27. package/dist/types/token-registry-functions/ownerOf.d.ts +19 -0
  28. package/dist/types/token-registry-functions/rejectTransfers.d.ts +43 -0
  29. package/dist/types/token-registry-functions/returnToken.d.ts +44 -0
  30. package/dist/types/token-registry-functions/transfer.d.ts +82 -0
  31. package/dist/types/token-registry-functions/types.d.ts +80 -0
  32. package/dist/types/token-registry-functions/utils.d.ts +13 -0
  33. package/package.json +1 -1
@@ -92,14 +92,12 @@ const getDocumentOwner = /* @__PURE__ */ __name(async (tokenRegistryAddress, tok
92
92
  const tokenRegistry = new Contract(tokenRegistryAddress, tokenRegistryAbi, provider);
93
93
  return await tokenRegistry.ownerOf(tokenId);
94
94
  }, "getDocumentOwner");
95
- const checkSupportsInterface = /* @__PURE__ */ __name(async (titleEscrowAddress, interfaceId, provider) => {
95
+ const checkSupportsInterface = /* @__PURE__ */ __name(async (contractAddress, interfaceId, provider) => {
96
96
  try {
97
97
  const Contract = ethers.getEthersContractFromProvider(provider);
98
- const titleEscrowAbi = [
99
- "function supportsInterface(bytes4 interfaceId) external view returns (bool)"
100
- ];
101
- const titleEscrowContract = new Contract(titleEscrowAddress, titleEscrowAbi, provider);
102
- return await titleEscrowContract.supportsInterface(interfaceId);
98
+ const abi = ["function supportsInterface(bytes4 interfaceId) external view returns (bool)"];
99
+ const contract = new Contract(contractAddress, abi, provider);
100
+ return await contract.supportsInterface(interfaceId);
103
101
  } catch {
104
102
  return false;
105
103
  }
@@ -165,6 +163,7 @@ const fetchEndorsementChain = /* @__PURE__ */ __name(async (tokenRegistryAddress
165
163
  }, "fetchEndorsementChain");
166
164
 
167
165
  exports.TitleEscrowInterface = TitleEscrowInterface;
166
+ exports.checkSupportsInterface = checkSupportsInterface;
168
167
  exports.fetchEndorsementChain = fetchEndorsementChain;
169
168
  exports.getDocumentOwner = getDocumentOwner;
170
169
  exports.getTitleEscrowAddress = getTitleEscrowAddress;
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 tokenRegistryFunctions = require('./token-registry-functions');
5
6
  var core = require('./core');
6
7
  var openAttestation = require('./open-attestation');
7
8
  var verify = require('./verify');
@@ -79,6 +80,12 @@ Object.defineProperty(exports, "v5Utils", {
79
80
  enumerable: true,
80
81
  get: function () { return tokenRegistryV5.v5Utils; }
81
82
  });
83
+ Object.keys(tokenRegistryFunctions).forEach(function (k) {
84
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
85
+ enumerable: true,
86
+ get: function () { return tokenRegistryFunctions[k]; }
87
+ });
88
+ });
82
89
  Object.keys(core).forEach(function (k) {
83
90
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
84
91
  enumerable: true,
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ var transfer = require('./transfer');
4
+ var rejectTransfers = require('./rejectTransfers');
5
+ var returnToken = require('./returnToken');
6
+ var mint = require('./mint');
7
+ var ownerOf = require('./ownerOf');
8
+
9
+
10
+
11
+ Object.keys(transfer).forEach(function (k) {
12
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
13
+ enumerable: true,
14
+ get: function () { return transfer[k]; }
15
+ });
16
+ });
17
+ Object.keys(rejectTransfers).forEach(function (k) {
18
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
19
+ enumerable: true,
20
+ get: function () { return rejectTransfers[k]; }
21
+ });
22
+ });
23
+ Object.keys(returnToken).forEach(function (k) {
24
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
25
+ enumerable: true,
26
+ get: function () { return returnToken[k]; }
27
+ });
28
+ });
29
+ Object.keys(mint).forEach(function (k) {
30
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
31
+ enumerable: true,
32
+ get: function () { return mint[k]; }
33
+ });
34
+ });
35
+ Object.keys(ownerOf).forEach(function (k) {
36
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
37
+ enumerable: true,
38
+ get: function () { return ownerOf[k]; }
39
+ });
40
+ });
@@ -0,0 +1,86 @@
1
+ 'use strict';
2
+
3
+ var core = require('../core');
4
+ var tokenRegistryV5 = require('../token-registry-v5');
5
+ var tokenRegistryV4 = require('../token-registry-v4');
6
+ var utils = require('./utils');
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ const mint = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
11
+ const { tokenRegistryAddress } = contractOptions;
12
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
13
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
14
+ if (!signer.provider) throw new Error("Provider is required");
15
+ const { beneficiaryAddress, holderAddress, tokenId, remarks } = params;
16
+ let isV5TT = titleEscrowVersion === "v5";
17
+ let isV4TT = titleEscrowVersion === "v4";
18
+ if (titleEscrowVersion === void 0) {
19
+ [isV4TT, isV5TT] = await Promise.all([
20
+ core.checkSupportsInterface(
21
+ tokenRegistryAddress,
22
+ tokenRegistryV4.v4SupportInterfaceIds.TradeTrustTokenMintable,
23
+ signer.provider
24
+ ),
25
+ core.checkSupportsInterface(
26
+ tokenRegistryAddress,
27
+ tokenRegistryV5.v5SupportInterfaceIds.TradeTrustTokenMintable,
28
+ signer.provider
29
+ )
30
+ ]);
31
+ }
32
+ if (!isV4TT && !isV5TT) {
33
+ throw new Error("Only Token Registry V4/V5 is supported");
34
+ }
35
+ let tradeTrustTokenContract;
36
+ if (isV5TT) {
37
+ tradeTrustTokenContract = tokenRegistryV5.v5Contracts.TradeTrustToken__factory.connect(
38
+ tokenRegistryAddress,
39
+ signer
40
+ );
41
+ } else if (isV4TT) {
42
+ tradeTrustTokenContract = tokenRegistryV4.v4Contracts.TradeTrustToken__factory.connect(
43
+ tokenRegistryAddress,
44
+ signer
45
+ );
46
+ }
47
+ const encryptedRemarks = remarks && isV5TT ? `0x${core.encrypt(remarks, options.id)}` : "0x";
48
+ try {
49
+ if (isV5TT) {
50
+ await tradeTrustTokenContract.callStatic.mint(
51
+ beneficiaryAddress,
52
+ holderAddress,
53
+ tokenId,
54
+ encryptedRemarks
55
+ );
56
+ } else if (isV4TT) {
57
+ await tradeTrustTokenContract.callStatic.mint(
58
+ beneficiaryAddress,
59
+ holderAddress,
60
+ tokenId
61
+ );
62
+ }
63
+ } catch (e) {
64
+ console.error("callStatic failed:", e);
65
+ throw new Error("Pre-check (callStatic) for mint failed");
66
+ }
67
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
68
+ if (isV5TT) {
69
+ return await tradeTrustTokenContract.mint(
70
+ beneficiaryAddress,
71
+ holderAddress,
72
+ tokenId,
73
+ encryptedRemarks,
74
+ txOptions
75
+ );
76
+ } else if (isV4TT) {
77
+ return await tradeTrustTokenContract.mint(
78
+ beneficiaryAddress,
79
+ holderAddress,
80
+ tokenId,
81
+ txOptions
82
+ );
83
+ }
84
+ }, "mint");
85
+
86
+ exports.mint = mint;
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ var core = require('../core');
4
+ var tokenRegistryV5 = require('../token-registry-v5');
5
+ var tokenRegistryV4 = require('../token-registry-v4');
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ const ownerOf = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
10
+ const { tokenRegistryAddress } = contractOptions;
11
+ const { titleEscrowVersion } = options;
12
+ const { tokenId } = params;
13
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
14
+ if (!signer.provider) throw new Error("Provider is required");
15
+ let isV5TT = titleEscrowVersion === "v5";
16
+ let isV4TT = titleEscrowVersion === "v4";
17
+ if (titleEscrowVersion === void 0) {
18
+ [isV4TT, isV5TT] = await Promise.all([
19
+ core.checkSupportsInterface(tokenRegistryAddress, tokenRegistryV4.v4SupportInterfaceIds.SBT, signer.provider),
20
+ core.checkSupportsInterface(tokenRegistryAddress, tokenRegistryV5.v5SupportInterfaceIds.SBT, signer.provider)
21
+ ]);
22
+ }
23
+ if (!isV4TT && !isV5TT) {
24
+ throw new Error("Only Token Registry V4/V5 is supported");
25
+ }
26
+ let tradeTrustTokenContract;
27
+ if (isV5TT) {
28
+ tradeTrustTokenContract = tokenRegistryV5.v5Contracts.TradeTrustToken__factory.connect(
29
+ tokenRegistryAddress,
30
+ signer
31
+ );
32
+ } else if (isV4TT) {
33
+ tradeTrustTokenContract = tokenRegistryV4.v4Contracts.TradeTrustToken__factory.connect(
34
+ tokenRegistryAddress,
35
+ signer
36
+ );
37
+ }
38
+ if (isV5TT) {
39
+ return await tradeTrustTokenContract.ownerOf(tokenId);
40
+ } else if (isV4TT) {
41
+ return await tradeTrustTokenContract.ownerOf(tokenId);
42
+ }
43
+ }, "ownerOf");
44
+
45
+ exports.ownerOf = ownerOf;
@@ -0,0 +1,123 @@
1
+ 'use strict';
2
+
3
+ var core = require('../core');
4
+ var tokenRegistryV5 = require('../token-registry-v5');
5
+ var utils = require('./utils');
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ const rejectTransferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
10
+ const { tokenRegistryAddress, tokenId } = contractOptions;
11
+ let { titleEscrowAddress } = contractOptions;
12
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
13
+ if (!titleEscrowAddress) {
14
+ titleEscrowAddress = await core.getTitleEscrowAddress(
15
+ tokenRegistryAddress,
16
+ tokenId,
17
+ signer.provider,
18
+ {}
19
+ );
20
+ }
21
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
22
+ if (!signer.provider) throw new Error("Provider is required");
23
+ const { remarks } = params;
24
+ const titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
25
+ const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
26
+ let isV5TT = titleEscrowVersion === "v5";
27
+ if (titleEscrowVersion === void 0) {
28
+ isV5TT = await core.isTitleEscrowVersion({
29
+ titleEscrowAddress,
30
+ versionInterface: core.TitleEscrowInterface.V5,
31
+ provider: signer.provider
32
+ });
33
+ }
34
+ if (!isV5TT) {
35
+ throw new Error("Only Token Registry V5 is supported");
36
+ }
37
+ try {
38
+ await titleEscrowContract.callStatic.rejectTransferHolder(encryptedRemarks);
39
+ } catch (e) {
40
+ console.error("callStatic failed:", e);
41
+ throw new Error("Pre-check (callStatic) for rejectTransferHolder failed");
42
+ }
43
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
44
+ return await titleEscrowContract.rejectTransferHolder(encryptedRemarks, txOptions);
45
+ }, "rejectTransferHolder");
46
+ const rejectTransferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
47
+ const { tokenRegistryAddress, tokenId } = contractOptions;
48
+ let { titleEscrowAddress } = contractOptions;
49
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
50
+ if (!titleEscrowAddress) {
51
+ titleEscrowAddress = await core.getTitleEscrowAddress(
52
+ tokenRegistryAddress,
53
+ tokenId,
54
+ signer.provider,
55
+ {}
56
+ );
57
+ }
58
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
59
+ if (!signer.provider) throw new Error("Provider is required");
60
+ const { remarks } = params;
61
+ const titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
62
+ const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
63
+ let isV5TT = titleEscrowVersion === "v5";
64
+ if (titleEscrowVersion === void 0) {
65
+ isV5TT = await core.isTitleEscrowVersion({
66
+ titleEscrowAddress,
67
+ versionInterface: core.TitleEscrowInterface.V5,
68
+ provider: signer.provider
69
+ });
70
+ }
71
+ if (!isV5TT) {
72
+ throw new Error("Only Token Registry V5 is supported");
73
+ }
74
+ try {
75
+ await titleEscrowContract.callStatic.rejectTransferBeneficiary(encryptedRemarks);
76
+ } catch (e) {
77
+ console.error("callStatic failed:", e);
78
+ throw new Error("Pre-check (callStatic) for rejectTransferBeneficiary failed");
79
+ }
80
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
81
+ return await titleEscrowContract.rejectTransferBeneficiary(encryptedRemarks, txOptions);
82
+ }, "rejectTransferBeneficiary");
83
+ const rejectTransferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
84
+ const { tokenRegistryAddress, tokenId } = contractOptions;
85
+ let { titleEscrowAddress } = contractOptions;
86
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
87
+ if (!titleEscrowAddress) {
88
+ titleEscrowAddress = await core.getTitleEscrowAddress(
89
+ tokenRegistryAddress,
90
+ tokenId,
91
+ signer.provider,
92
+ {}
93
+ );
94
+ }
95
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
96
+ if (!signer.provider) throw new Error("Provider is required");
97
+ const { remarks } = params;
98
+ const titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
99
+ const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
100
+ let isV5TT = titleEscrowVersion === "v5";
101
+ if (titleEscrowVersion === void 0) {
102
+ isV5TT = await core.isTitleEscrowVersion({
103
+ titleEscrowAddress,
104
+ versionInterface: core.TitleEscrowInterface.V5,
105
+ provider: signer.provider
106
+ });
107
+ }
108
+ if (!isV5TT) {
109
+ throw new Error("Only Token Registry V5 is supported");
110
+ }
111
+ try {
112
+ await titleEscrowContract.callStatic.rejectTransferOwners(encryptedRemarks);
113
+ } catch (e) {
114
+ console.error("callStatic failed:", e);
115
+ throw new Error("Pre-check (callStatic) for rejectTransferOwners failed");
116
+ }
117
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
118
+ return await titleEscrowContract.rejectTransferOwners(encryptedRemarks, txOptions);
119
+ }, "rejectTransferOwners");
120
+
121
+ exports.rejectTransferBeneficiary = rejectTransferBeneficiary;
122
+ exports.rejectTransferHolder = rejectTransferHolder;
123
+ exports.rejectTransferOwners = rejectTransferOwners;
@@ -0,0 +1,204 @@
1
+ 'use strict';
2
+
3
+ var core = require('../core');
4
+ var tokenRegistryV5 = require('../token-registry-v5');
5
+ var tokenRegistryV4 = require('../token-registry-v4');
6
+ var utils = require('./utils');
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ const returnToIssuer = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
11
+ const { tokenRegistryAddress, tokenId } = contractOptions;
12
+ let { titleEscrowAddress } = contractOptions;
13
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
14
+ if (!titleEscrowAddress) {
15
+ titleEscrowAddress = await core.getTitleEscrowAddress(
16
+ tokenRegistryAddress,
17
+ tokenId,
18
+ signer.provider,
19
+ {}
20
+ );
21
+ }
22
+ if (!titleEscrowAddress) throw new Error("Title Escrow address is required");
23
+ if (!signer.provider) throw new Error("Provider is required");
24
+ const { remarks } = params;
25
+ let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
26
+ const encryptedRemarks = remarks && options.id ? `0x${core.encrypt(remarks, options.id)}` : "0x";
27
+ let isV5TT = titleEscrowVersion === "v5";
28
+ let isV4TT = titleEscrowVersion === "v4";
29
+ if (titleEscrowVersion === void 0) {
30
+ [isV4TT, isV5TT] = await Promise.all([
31
+ await core.isTitleEscrowVersion({
32
+ titleEscrowAddress,
33
+ versionInterface: core.TitleEscrowInterface.V4,
34
+ provider: signer.provider
35
+ }),
36
+ await core.isTitleEscrowVersion({
37
+ titleEscrowAddress,
38
+ versionInterface: core.TitleEscrowInterface.V5,
39
+ provider: signer.provider
40
+ })
41
+ ]);
42
+ }
43
+ if (!isV5TT && !isV4TT) {
44
+ throw new Error("Only Token Registry V4/V5 is supported");
45
+ }
46
+ if (isV4TT) {
47
+ titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
48
+ titleEscrowAddress,
49
+ signer
50
+ );
51
+ }
52
+ try {
53
+ if (isV5TT) {
54
+ await titleEscrowContract.callStatic.returnToIssuer(
55
+ encryptedRemarks
56
+ );
57
+ } else if (isV4TT) {
58
+ await titleEscrowContract.callStatic.surrender();
59
+ }
60
+ } catch (e) {
61
+ console.error("callStatic failed:", e);
62
+ throw new Error("Pre-check (callStatic) for returnToIssuer failed");
63
+ }
64
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
65
+ if (isV5TT) {
66
+ return await titleEscrowContract.returnToIssuer(
67
+ encryptedRemarks,
68
+ txOptions
69
+ );
70
+ } else if (isV4TT) {
71
+ return await titleEscrowContract.surrender(txOptions);
72
+ }
73
+ }, "returnToIssuer");
74
+ const rejectReturned = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
75
+ const { tokenRegistryAddress } = contractOptions;
76
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
77
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
78
+ if (!signer.provider) throw new Error("Provider is required");
79
+ const { tokenId, remarks } = params;
80
+ let isV5TT = titleEscrowVersion === "v5";
81
+ let isV4TT = titleEscrowVersion === "v4";
82
+ if (titleEscrowVersion === void 0) {
83
+ [isV4TT, isV5TT] = await Promise.all([
84
+ core.checkSupportsInterface(
85
+ tokenRegistryAddress,
86
+ tokenRegistryV4.v4SupportInterfaceIds.TradeTrustTokenRestorable,
87
+ signer.provider
88
+ ),
89
+ core.checkSupportsInterface(
90
+ tokenRegistryAddress,
91
+ tokenRegistryV5.v5SupportInterfaceIds.TradeTrustTokenRestorable,
92
+ signer.provider
93
+ )
94
+ ]);
95
+ }
96
+ if (!isV4TT && !isV5TT) {
97
+ throw new Error("Only Token Registry V4/V5 is supported");
98
+ }
99
+ let tradeTrustTokenContract;
100
+ if (isV5TT) {
101
+ tradeTrustTokenContract = tokenRegistryV5.v5Contracts.TradeTrustToken__factory.connect(
102
+ tokenRegistryAddress,
103
+ signer
104
+ );
105
+ } else if (isV4TT) {
106
+ tradeTrustTokenContract = tokenRegistryV4.v4Contracts.TradeTrustToken__factory.connect(
107
+ tokenRegistryAddress,
108
+ signer
109
+ );
110
+ }
111
+ const encryptedRemarks = remarks && isV5TT ? `0x${core.encrypt(remarks, options.id)}` : "0x";
112
+ try {
113
+ if (isV5TT) {
114
+ await tradeTrustTokenContract.callStatic.restore(
115
+ tokenId,
116
+ encryptedRemarks
117
+ );
118
+ } else if (isV4TT) {
119
+ await tradeTrustTokenContract.callStatic.restore(tokenId);
120
+ }
121
+ } catch (e) {
122
+ console.error("callStatic failed:", e);
123
+ throw new Error("Pre-check (callStatic) for rejectReturned failed");
124
+ }
125
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
126
+ if (isV5TT) {
127
+ return await tradeTrustTokenContract.restore(
128
+ tokenId,
129
+ encryptedRemarks,
130
+ txOptions
131
+ );
132
+ } else if (isV4TT) {
133
+ return await tradeTrustTokenContract.restore(
134
+ tokenId,
135
+ txOptions
136
+ );
137
+ }
138
+ }, "rejectReturned");
139
+ const acceptReturned = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
140
+ const { tokenRegistryAddress } = contractOptions;
141
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
142
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
143
+ if (!signer.provider) throw new Error("Provider is required");
144
+ const { tokenId, remarks } = params;
145
+ let isV5TT = titleEscrowVersion === "v5";
146
+ let isV4TT = titleEscrowVersion === "v4";
147
+ if (titleEscrowVersion === void 0) {
148
+ [isV4TT, isV5TT] = await Promise.all([
149
+ core.checkSupportsInterface(
150
+ tokenRegistryAddress,
151
+ tokenRegistryV4.v4SupportInterfaceIds.TradeTrustTokenBurnable,
152
+ signer.provider
153
+ ),
154
+ core.checkSupportsInterface(
155
+ tokenRegistryAddress,
156
+ tokenRegistryV5.v5SupportInterfaceIds.TradeTrustTokenBurnable,
157
+ signer.provider
158
+ )
159
+ ]);
160
+ }
161
+ if (!isV4TT && !isV5TT) {
162
+ throw new Error("Only Token Registry V4/V5 is supported");
163
+ }
164
+ let tradeTrustTokenContract;
165
+ if (isV5TT) {
166
+ tradeTrustTokenContract = tokenRegistryV5.v5Contracts.TradeTrustToken__factory.connect(
167
+ tokenRegistryAddress,
168
+ signer
169
+ );
170
+ } else if (isV4TT) {
171
+ tradeTrustTokenContract = tokenRegistryV4.v4Contracts.TradeTrustToken__factory.connect(
172
+ tokenRegistryAddress,
173
+ signer
174
+ );
175
+ }
176
+ const encryptedRemarks = remarks && isV5TT ? `0x${core.encrypt(remarks, options.id)}` : "0x";
177
+ try {
178
+ if (isV5TT) {
179
+ await tradeTrustTokenContract.callStatic.burn(
180
+ tokenId,
181
+ encryptedRemarks
182
+ );
183
+ } else if (isV4TT) {
184
+ await tradeTrustTokenContract.callStatic.burn(tokenId);
185
+ }
186
+ } catch (e) {
187
+ console.error("callStatic failed:", e);
188
+ throw new Error("Pre-check (callStatic) for acceptReturned failed");
189
+ }
190
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
191
+ if (isV5TT) {
192
+ return await tradeTrustTokenContract.burn(
193
+ tokenId,
194
+ encryptedRemarks,
195
+ txOptions
196
+ );
197
+ } else if (isV4TT) {
198
+ return await tradeTrustTokenContract.burn(tokenId, txOptions);
199
+ }
200
+ }, "acceptReturned");
201
+
202
+ exports.acceptReturned = acceptReturned;
203
+ exports.rejectReturned = rejectReturned;
204
+ exports.returnToIssuer = returnToIssuer;