@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
@@ -0,0 +1,305 @@
1
+ 'use strict';
2
+
3
+ var core = require('../core');
4
+ var tokenRegistryV4 = require('../token-registry-v4');
5
+ var tokenRegistryV5 = require('../token-registry-v5');
6
+ var utils = require('./utils');
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ const transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
11
+ const { tokenRegistryAddress, tokenId } = contractOptions;
12
+ const { titleEscrowVersion } = options;
13
+ let { titleEscrowAddress } = contractOptions;
14
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
15
+ let isV5TT = titleEscrowVersion === "v5";
16
+ let isV4TT = titleEscrowVersion === "v4";
17
+ if (!titleEscrowAddress) {
18
+ titleEscrowAddress = await core.getTitleEscrowAddress(
19
+ tokenRegistryAddress,
20
+ tokenId,
21
+ signer.provider,
22
+ { titleEscrowVersion }
23
+ );
24
+ }
25
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
26
+ if (!signer.provider) throw new Error("Provider is required");
27
+ const { holderAddress, remarks } = params;
28
+ let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
29
+ const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
30
+ if (titleEscrowVersion === void 0) {
31
+ [isV4TT, isV5TT] = await Promise.all([
32
+ core.isTitleEscrowVersion({
33
+ titleEscrowAddress,
34
+ versionInterface: core.TitleEscrowInterface.V4,
35
+ provider: signer.provider
36
+ }),
37
+ core.isTitleEscrowVersion({
38
+ titleEscrowAddress,
39
+ versionInterface: core.TitleEscrowInterface.V5,
40
+ provider: signer.provider
41
+ })
42
+ ]);
43
+ }
44
+ if (!isV4TT && !isV5TT) {
45
+ throw new Error("Only Token Registry V4/V5 is supported");
46
+ }
47
+ if (isV4TT) {
48
+ titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
49
+ titleEscrowAddress,
50
+ signer
51
+ );
52
+ }
53
+ try {
54
+ if (isV5TT) {
55
+ await titleEscrowContract.callStatic.transferHolder(
56
+ holderAddress,
57
+ encryptedRemarks
58
+ );
59
+ } else if (isV4TT) {
60
+ await titleEscrowContract.callStatic.transferHolder(
61
+ holderAddress
62
+ );
63
+ }
64
+ } catch (e) {
65
+ console.error("callStatic failed:", e);
66
+ throw new Error("Pre-check (callStatic) for transferHolder failed");
67
+ }
68
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
69
+ if (isV5TT) {
70
+ return await titleEscrowContract.transferHolder(
71
+ holderAddress,
72
+ encryptedRemarks,
73
+ txOptions
74
+ );
75
+ } else if (isV4TT) {
76
+ return await titleEscrowContract.transferHolder(
77
+ holderAddress,
78
+ txOptions
79
+ );
80
+ }
81
+ }, "transferHolder");
82
+ const transferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
83
+ const { tokenId, tokenRegistryAddress } = contractOptions;
84
+ const { titleEscrowVersion } = options;
85
+ let { titleEscrowAddress } = contractOptions;
86
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
87
+ let isV5TT = titleEscrowVersion === "v5";
88
+ let isV4TT = titleEscrowVersion === "v4";
89
+ if (!titleEscrowAddress) {
90
+ titleEscrowAddress = await core.getTitleEscrowAddress(
91
+ tokenRegistryAddress,
92
+ tokenId,
93
+ signer.provider,
94
+ { titleEscrowVersion }
95
+ );
96
+ }
97
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
98
+ if (!signer.provider) throw new Error("Provider is required");
99
+ const { newBeneficiaryAddress, remarks } = params;
100
+ let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
101
+ const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
102
+ if (titleEscrowVersion === void 0) {
103
+ [isV4TT, isV5TT] = await Promise.all([
104
+ core.isTitleEscrowVersion({
105
+ titleEscrowAddress,
106
+ versionInterface: core.TitleEscrowInterface.V4,
107
+ provider: signer.provider
108
+ }),
109
+ core.isTitleEscrowVersion({
110
+ titleEscrowAddress,
111
+ versionInterface: core.TitleEscrowInterface.V5,
112
+ provider: signer.provider
113
+ })
114
+ ]);
115
+ }
116
+ if (!isV4TT && !isV5TT) {
117
+ throw new Error("Only Token Registry V4/V5 is supported");
118
+ }
119
+ if (!isV5TT) {
120
+ titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
121
+ titleEscrowAddress,
122
+ signer
123
+ );
124
+ }
125
+ try {
126
+ if (isV5TT) {
127
+ await titleEscrowContract.callStatic.transferBeneficiary(
128
+ newBeneficiaryAddress,
129
+ encryptedRemarks
130
+ );
131
+ } else if (isV4TT) {
132
+ await titleEscrowContract.callStatic.transferBeneficiary(
133
+ newBeneficiaryAddress
134
+ );
135
+ }
136
+ } catch (e) {
137
+ console.error("callStatic failed:", e);
138
+ throw new Error("Pre-check (callStatic) for transferBeneficiary failed");
139
+ }
140
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
141
+ if (isV5TT) {
142
+ const tx = await titleEscrowContract.transferBeneficiary(
143
+ newBeneficiaryAddress,
144
+ encryptedRemarks,
145
+ txOptions
146
+ );
147
+ return tx;
148
+ } else if (isV4TT) {
149
+ const tx = await titleEscrowContract.transferBeneficiary(
150
+ newBeneficiaryAddress,
151
+ txOptions
152
+ );
153
+ return tx;
154
+ }
155
+ }, "transferBeneficiary");
156
+ const transferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
157
+ const { tokenId, tokenRegistryAddress } = contractOptions;
158
+ const { titleEscrowVersion } = options;
159
+ let { titleEscrowAddress } = contractOptions;
160
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
161
+ let isV5TT = titleEscrowVersion === "v5";
162
+ let isV4TT = titleEscrowVersion === "v4";
163
+ if (!titleEscrowAddress) {
164
+ titleEscrowAddress = await core.getTitleEscrowAddress(
165
+ tokenRegistryAddress,
166
+ tokenId,
167
+ signer.provider,
168
+ { titleEscrowVersion }
169
+ );
170
+ }
171
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
172
+ if (!signer.provider) throw new Error("Provider is required");
173
+ const { newBeneficiaryAddress, newHolderAddress, remarks } = params;
174
+ let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
175
+ const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
176
+ if (titleEscrowVersion === void 0) {
177
+ [isV4TT, isV5TT] = await Promise.all([
178
+ core.isTitleEscrowVersion({
179
+ titleEscrowAddress,
180
+ versionInterface: core.TitleEscrowInterface.V4,
181
+ provider: signer.provider
182
+ }),
183
+ core.isTitleEscrowVersion({
184
+ titleEscrowAddress,
185
+ versionInterface: core.TitleEscrowInterface.V5,
186
+ provider: signer.provider
187
+ })
188
+ ]);
189
+ }
190
+ if (!isV4TT && !isV5TT) {
191
+ throw new Error("Only Token Registry V4/V5 is supported");
192
+ }
193
+ if (!isV5TT) {
194
+ titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
195
+ titleEscrowAddress,
196
+ signer
197
+ );
198
+ }
199
+ try {
200
+ if (isV5TT) {
201
+ await titleEscrowContract.callStatic.transferOwners(
202
+ newBeneficiaryAddress,
203
+ newHolderAddress,
204
+ encryptedRemarks
205
+ );
206
+ } else if (isV4TT) {
207
+ await titleEscrowContract.callStatic.transferOwners(
208
+ newBeneficiaryAddress,
209
+ newHolderAddress
210
+ );
211
+ }
212
+ } catch (e) {
213
+ console.error("callStatic failed:", e);
214
+ throw new Error("Pre-check (callStatic) for transferOwners failed");
215
+ }
216
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
217
+ if (isV5TT) {
218
+ return await titleEscrowContract.transferOwners(
219
+ newBeneficiaryAddress,
220
+ newHolderAddress,
221
+ encryptedRemarks,
222
+ txOptions
223
+ );
224
+ } else if (isV4TT) {
225
+ return await titleEscrowContract.transferOwners(
226
+ newBeneficiaryAddress,
227
+ newHolderAddress,
228
+ txOptions
229
+ );
230
+ }
231
+ }, "transferOwners");
232
+ const nominate = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
233
+ const { tokenId, tokenRegistryAddress } = contractOptions;
234
+ const { titleEscrowVersion } = options;
235
+ let { titleEscrowAddress } = contractOptions;
236
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
237
+ let isV5TT = titleEscrowVersion === "v5";
238
+ let isV4TT = titleEscrowVersion === "v4";
239
+ if (!titleEscrowAddress) {
240
+ titleEscrowAddress = await core.getTitleEscrowAddress(
241
+ tokenRegistryAddress,
242
+ tokenId,
243
+ signer.provider,
244
+ { titleEscrowVersion }
245
+ );
246
+ }
247
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
248
+ if (!signer.provider) throw new Error("Provider is required");
249
+ const { newBeneficiaryAddress, remarks } = params;
250
+ let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
251
+ const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
252
+ if (titleEscrowVersion === void 0) {
253
+ [isV4TT, isV5TT] = await Promise.all([
254
+ core.isTitleEscrowVersion({
255
+ titleEscrowAddress,
256
+ versionInterface: core.TitleEscrowInterface.V4,
257
+ provider: signer.provider
258
+ }),
259
+ core.isTitleEscrowVersion({
260
+ titleEscrowAddress,
261
+ versionInterface: core.TitleEscrowInterface.V5,
262
+ provider: signer.provider
263
+ })
264
+ ]);
265
+ }
266
+ if (!isV5TT) {
267
+ titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
268
+ titleEscrowAddress,
269
+ signer
270
+ );
271
+ }
272
+ try {
273
+ if (isV5TT) {
274
+ await titleEscrowContract.callStatic.nominate(
275
+ newBeneficiaryAddress,
276
+ encryptedRemarks
277
+ );
278
+ } else if (isV4TT) {
279
+ await titleEscrowContract.callStatic.nominate(
280
+ newBeneficiaryAddress
281
+ );
282
+ }
283
+ } catch (e) {
284
+ console.error("callStatic failed:", e);
285
+ throw new Error("Pre-check (callStatic) for nominate failed");
286
+ }
287
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
288
+ if (isV5TT) {
289
+ return await titleEscrowContract.nominate(
290
+ newBeneficiaryAddress,
291
+ encryptedRemarks,
292
+ txOptions
293
+ );
294
+ } else if (isV4TT) {
295
+ return await titleEscrowContract.nominate(
296
+ newBeneficiaryAddress,
297
+ txOptions
298
+ );
299
+ }
300
+ }, "nominate");
301
+
302
+ exports.nominate = nominate;
303
+ exports.transferBeneficiary = transferBeneficiary;
304
+ exports.transferHolder = transferHolder;
305
+ exports.transferOwners = transferOwners;
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var ethers = require('../utils/ethers');
4
+ var tradetrustUtils = require('@tradetrust-tt/tradetrust-utils');
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ const getTxOptions = /* @__PURE__ */ __name(async (signer, chainId, maxFeePerGas, maxPriorityFeePerGas) => {
9
+ if (!maxFeePerGas || !maxPriorityFeePerGas) {
10
+ chainId = chainId ?? await getChainIdSafe(signer);
11
+ const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
12
+ if (gasStation) {
13
+ const gasFees = await gasStation();
14
+ maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
15
+ maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
16
+ }
17
+ }
18
+ return maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
19
+ }, "getTxOptions");
20
+ const getChainIdSafe = /* @__PURE__ */ __name(async (signer) => {
21
+ if (ethers.isV6EthersProvider(signer.provider)) {
22
+ const network = await signer.provider?.getNetwork();
23
+ if (!network?.chainId) throw new Error("Cannot determine chainId: provider is missing");
24
+ return network.chainId;
25
+ }
26
+ return await signer.getChainId();
27
+ }, "getChainIdSafe");
28
+ const getSignerAddressSafe = /* @__PURE__ */ __name(async (signer) => {
29
+ if (ethers.isV6EthersProvider(signer.provider)) {
30
+ return await signer.getAddress();
31
+ }
32
+ return await signer.getAddress();
33
+ }, "getSignerAddressSafe");
34
+
35
+ exports.getChainIdSafe = getChainIdSafe;
36
+ exports.getSignerAddressSafe = getSignerAddressSafe;
37
+ exports.getTxOptions = getTxOptions;
@@ -90,14 +90,12 @@ const getDocumentOwner = /* @__PURE__ */ __name(async (tokenRegistryAddress, tok
90
90
  const tokenRegistry = new Contract(tokenRegistryAddress, tokenRegistryAbi, provider);
91
91
  return await tokenRegistry.ownerOf(tokenId);
92
92
  }, "getDocumentOwner");
93
- const checkSupportsInterface = /* @__PURE__ */ __name(async (titleEscrowAddress, interfaceId, provider) => {
93
+ const checkSupportsInterface = /* @__PURE__ */ __name(async (contractAddress, interfaceId, provider) => {
94
94
  try {
95
95
  const Contract = getEthersContractFromProvider(provider);
96
- const titleEscrowAbi = [
97
- "function supportsInterface(bytes4 interfaceId) external view returns (bool)"
98
- ];
99
- const titleEscrowContract = new Contract(titleEscrowAddress, titleEscrowAbi, provider);
100
- return await titleEscrowContract.supportsInterface(interfaceId);
96
+ const abi = ["function supportsInterface(bytes4 interfaceId) external view returns (bool)"];
97
+ const contract = new Contract(contractAddress, abi, provider);
98
+ return await contract.supportsInterface(interfaceId);
101
99
  } catch {
102
100
  return false;
103
101
  }
@@ -162,4 +160,4 @@ const fetchEndorsementChain = /* @__PURE__ */ __name(async (tokenRegistryAddress
162
160
  }));
163
161
  }, "fetchEndorsementChain");
164
162
 
165
- export { TitleEscrowInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion };
163
+ export { TitleEscrowInterface, checkSupportsInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion };
package/dist/esm/index.js CHANGED
@@ -1,5 +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 * from './token-registry-functions';
3
4
  export * from './core';
4
5
  export * from './open-attestation';
5
6
  export * from './verify';
@@ -0,0 +1,5 @@
1
+ export * from './transfer';
2
+ export * from './rejectTransfers';
3
+ export * from './returnToken';
4
+ export * from './mint';
5
+ export * from './ownerOf';
@@ -0,0 +1,84 @@
1
+ import { checkSupportsInterface, encrypt } from '../core';
2
+ import { v5SupportInterfaceIds, v5Contracts } from '../token-registry-v5';
3
+ import { v4SupportInterfaceIds, v4Contracts } from '../token-registry-v4';
4
+ import { getTxOptions } from './utils';
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ const mint = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
9
+ const { tokenRegistryAddress } = contractOptions;
10
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
11
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
12
+ if (!signer.provider) throw new Error("Provider is required");
13
+ const { beneficiaryAddress, holderAddress, tokenId, remarks } = params;
14
+ let isV5TT = titleEscrowVersion === "v5";
15
+ let isV4TT = titleEscrowVersion === "v4";
16
+ if (titleEscrowVersion === void 0) {
17
+ [isV4TT, isV5TT] = await Promise.all([
18
+ checkSupportsInterface(
19
+ tokenRegistryAddress,
20
+ v4SupportInterfaceIds.TradeTrustTokenMintable,
21
+ signer.provider
22
+ ),
23
+ checkSupportsInterface(
24
+ tokenRegistryAddress,
25
+ v5SupportInterfaceIds.TradeTrustTokenMintable,
26
+ signer.provider
27
+ )
28
+ ]);
29
+ }
30
+ if (!isV4TT && !isV5TT) {
31
+ throw new Error("Only Token Registry V4/V5 is supported");
32
+ }
33
+ let tradeTrustTokenContract;
34
+ if (isV5TT) {
35
+ tradeTrustTokenContract = v5Contracts.TradeTrustToken__factory.connect(
36
+ tokenRegistryAddress,
37
+ signer
38
+ );
39
+ } else if (isV4TT) {
40
+ tradeTrustTokenContract = v4Contracts.TradeTrustToken__factory.connect(
41
+ tokenRegistryAddress,
42
+ signer
43
+ );
44
+ }
45
+ const encryptedRemarks = remarks && isV5TT ? `0x${encrypt(remarks, options.id)}` : "0x";
46
+ try {
47
+ if (isV5TT) {
48
+ await tradeTrustTokenContract.callStatic.mint(
49
+ beneficiaryAddress,
50
+ holderAddress,
51
+ tokenId,
52
+ encryptedRemarks
53
+ );
54
+ } else if (isV4TT) {
55
+ await tradeTrustTokenContract.callStatic.mint(
56
+ beneficiaryAddress,
57
+ holderAddress,
58
+ tokenId
59
+ );
60
+ }
61
+ } catch (e) {
62
+ console.error("callStatic failed:", e);
63
+ throw new Error("Pre-check (callStatic) for mint failed");
64
+ }
65
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
66
+ if (isV5TT) {
67
+ return await tradeTrustTokenContract.mint(
68
+ beneficiaryAddress,
69
+ holderAddress,
70
+ tokenId,
71
+ encryptedRemarks,
72
+ txOptions
73
+ );
74
+ } else if (isV4TT) {
75
+ return await tradeTrustTokenContract.mint(
76
+ beneficiaryAddress,
77
+ holderAddress,
78
+ tokenId,
79
+ txOptions
80
+ );
81
+ }
82
+ }, "mint");
83
+
84
+ export { mint };
@@ -0,0 +1,43 @@
1
+ import { checkSupportsInterface } from '../core';
2
+ import { v5SupportInterfaceIds, v5Contracts } from '../token-registry-v5';
3
+ import { v4SupportInterfaceIds, v4Contracts } from '../token-registry-v4';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ const ownerOf = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
8
+ const { tokenRegistryAddress } = contractOptions;
9
+ const { titleEscrowVersion } = options;
10
+ const { tokenId } = params;
11
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
12
+ if (!signer.provider) throw new Error("Provider is required");
13
+ let isV5TT = titleEscrowVersion === "v5";
14
+ let isV4TT = titleEscrowVersion === "v4";
15
+ if (titleEscrowVersion === void 0) {
16
+ [isV4TT, isV5TT] = await Promise.all([
17
+ checkSupportsInterface(tokenRegistryAddress, v4SupportInterfaceIds.SBT, signer.provider),
18
+ checkSupportsInterface(tokenRegistryAddress, v5SupportInterfaceIds.SBT, signer.provider)
19
+ ]);
20
+ }
21
+ if (!isV4TT && !isV5TT) {
22
+ throw new Error("Only Token Registry V4/V5 is supported");
23
+ }
24
+ let tradeTrustTokenContract;
25
+ if (isV5TT) {
26
+ tradeTrustTokenContract = v5Contracts.TradeTrustToken__factory.connect(
27
+ tokenRegistryAddress,
28
+ signer
29
+ );
30
+ } else if (isV4TT) {
31
+ tradeTrustTokenContract = v4Contracts.TradeTrustToken__factory.connect(
32
+ tokenRegistryAddress,
33
+ signer
34
+ );
35
+ }
36
+ if (isV5TT) {
37
+ return await tradeTrustTokenContract.ownerOf(tokenId);
38
+ } else if (isV4TT) {
39
+ return await tradeTrustTokenContract.ownerOf(tokenId);
40
+ }
41
+ }, "ownerOf");
42
+
43
+ export { ownerOf };
@@ -0,0 +1,119 @@
1
+ import { getTitleEscrowAddress, encrypt, isTitleEscrowVersion, TitleEscrowInterface } from '../core';
2
+ import { v5Contracts } from '../token-registry-v5';
3
+ import { getTxOptions } from './utils';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ const rejectTransferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
8
+ const { tokenRegistryAddress, tokenId } = contractOptions;
9
+ let { titleEscrowAddress } = contractOptions;
10
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
11
+ if (!titleEscrowAddress) {
12
+ titleEscrowAddress = await getTitleEscrowAddress(
13
+ tokenRegistryAddress,
14
+ tokenId,
15
+ signer.provider,
16
+ {}
17
+ );
18
+ }
19
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
20
+ if (!signer.provider) throw new Error("Provider is required");
21
+ const { remarks } = params;
22
+ const titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
23
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
24
+ let isV5TT = titleEscrowVersion === "v5";
25
+ if (titleEscrowVersion === void 0) {
26
+ isV5TT = await isTitleEscrowVersion({
27
+ titleEscrowAddress,
28
+ versionInterface: TitleEscrowInterface.V5,
29
+ provider: signer.provider
30
+ });
31
+ }
32
+ if (!isV5TT) {
33
+ throw new Error("Only Token Registry V5 is supported");
34
+ }
35
+ try {
36
+ await titleEscrowContract.callStatic.rejectTransferHolder(encryptedRemarks);
37
+ } catch (e) {
38
+ console.error("callStatic failed:", e);
39
+ throw new Error("Pre-check (callStatic) for rejectTransferHolder failed");
40
+ }
41
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
42
+ return await titleEscrowContract.rejectTransferHolder(encryptedRemarks, txOptions);
43
+ }, "rejectTransferHolder");
44
+ const rejectTransferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
45
+ const { tokenRegistryAddress, tokenId } = contractOptions;
46
+ let { titleEscrowAddress } = contractOptions;
47
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
48
+ if (!titleEscrowAddress) {
49
+ titleEscrowAddress = await getTitleEscrowAddress(
50
+ tokenRegistryAddress,
51
+ tokenId,
52
+ signer.provider,
53
+ {}
54
+ );
55
+ }
56
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
57
+ if (!signer.provider) throw new Error("Provider is required");
58
+ const { remarks } = params;
59
+ const titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
60
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
61
+ let isV5TT = titleEscrowVersion === "v5";
62
+ if (titleEscrowVersion === void 0) {
63
+ isV5TT = await isTitleEscrowVersion({
64
+ titleEscrowAddress,
65
+ versionInterface: TitleEscrowInterface.V5,
66
+ provider: signer.provider
67
+ });
68
+ }
69
+ if (!isV5TT) {
70
+ throw new Error("Only Token Registry V5 is supported");
71
+ }
72
+ try {
73
+ await titleEscrowContract.callStatic.rejectTransferBeneficiary(encryptedRemarks);
74
+ } catch (e) {
75
+ console.error("callStatic failed:", e);
76
+ throw new Error("Pre-check (callStatic) for rejectTransferBeneficiary failed");
77
+ }
78
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
79
+ return await titleEscrowContract.rejectTransferBeneficiary(encryptedRemarks, txOptions);
80
+ }, "rejectTransferBeneficiary");
81
+ const rejectTransferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
82
+ const { tokenRegistryAddress, tokenId } = contractOptions;
83
+ let { titleEscrowAddress } = contractOptions;
84
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
85
+ if (!titleEscrowAddress) {
86
+ titleEscrowAddress = await getTitleEscrowAddress(
87
+ tokenRegistryAddress,
88
+ tokenId,
89
+ signer.provider,
90
+ {}
91
+ );
92
+ }
93
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
94
+ if (!signer.provider) throw new Error("Provider is required");
95
+ const { remarks } = params;
96
+ const titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
97
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
98
+ let isV5TT = titleEscrowVersion === "v5";
99
+ if (titleEscrowVersion === void 0) {
100
+ isV5TT = await isTitleEscrowVersion({
101
+ titleEscrowAddress,
102
+ versionInterface: TitleEscrowInterface.V5,
103
+ provider: signer.provider
104
+ });
105
+ }
106
+ if (!isV5TT) {
107
+ throw new Error("Only Token Registry V5 is supported");
108
+ }
109
+ try {
110
+ await titleEscrowContract.callStatic.rejectTransferOwners(encryptedRemarks);
111
+ } catch (e) {
112
+ console.error("callStatic failed:", e);
113
+ throw new Error("Pre-check (callStatic) for rejectTransferOwners failed");
114
+ }
115
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
116
+ return await titleEscrowContract.rejectTransferOwners(encryptedRemarks, txOptions);
117
+ }, "rejectTransferOwners");
118
+
119
+ export { rejectTransferBeneficiary, rejectTransferHolder, rejectTransferOwners };