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