@trustvc/trustvc 1.5.4 → 1.6.0-alpha.1

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.
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,12 @@
1
+ 'use strict';
2
+
3
+ var transfer = require('./transfer');
4
+
5
+
6
+
7
+ Object.keys(transfer).forEach(function (k) {
8
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
9
+ enumerable: true,
10
+ get: function () { return transfer[k]; }
11
+ });
12
+ });
@@ -0,0 +1,347 @@
1
+ 'use strict';
2
+
3
+ var tradetrustUtils = require('@tradetrust-tt/tradetrust-utils');
4
+ var core = require('src/core');
5
+ var tokenRegistryV4 = require('src/token-registry-v4');
6
+ var tokenRegistryV5 = require('src/token-registry-v5');
7
+ var ethers = require('src/utils/ethers');
8
+
9
+ var __defProp = Object.defineProperty;
10
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
+ const getChainIdSafe = /* @__PURE__ */ __name(async (signer) => {
12
+ if (ethers.isV6EthersProvider(signer.provider)) {
13
+ const network = await signer.provider?.getNetwork();
14
+ if (!network?.chainId) throw new Error("Cannot determine chainId: provider is missing");
15
+ return network.chainId;
16
+ }
17
+ return await signer.getChainId();
18
+ }, "getChainIdSafe");
19
+ const transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
20
+ const { tokenRegistryAddress, tokenId } = contractOptions;
21
+ const { titleEscrowVersion } = options;
22
+ let { titleEscrowAddress } = contractOptions;
23
+ let { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
24
+ let isV5TT = titleEscrowVersion === "v5";
25
+ let isV4TT = titleEscrowVersion === "v4";
26
+ if (!titleEscrowAddress) {
27
+ titleEscrowAddress = await core.getTitleEscrowAddress(
28
+ tokenRegistryAddress,
29
+ tokenId,
30
+ signer.provider,
31
+ { titleEscrowVersion }
32
+ );
33
+ }
34
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
35
+ if (!signer.provider) throw new Error("Provider is required");
36
+ const { holderAddress, remarks } = params;
37
+ let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
38
+ const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
39
+ if (titleEscrowVersion === void 0) {
40
+ [isV4TT, isV5TT] = await Promise.all([
41
+ core.isTitleEscrowVersion({
42
+ titleEscrowAddress,
43
+ versionInterface: core.TitleEscrowInterface.V4,
44
+ provider: signer.provider
45
+ }),
46
+ core.isTitleEscrowVersion({
47
+ titleEscrowAddress,
48
+ versionInterface: core.TitleEscrowInterface.V5,
49
+ provider: signer.provider
50
+ })
51
+ ]);
52
+ }
53
+ if (!isV4TT && !isV5TT) {
54
+ throw new Error("Only Token Registry V4/V5 is supported");
55
+ }
56
+ if (isV4TT) {
57
+ titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
58
+ titleEscrowAddress,
59
+ signer
60
+ );
61
+ }
62
+ try {
63
+ if (isV5TT) {
64
+ await titleEscrowContract.callStatic.transferHolder(
65
+ holderAddress,
66
+ encryptedRemarks
67
+ );
68
+ } else if (isV4TT) {
69
+ await titleEscrowContract.callStatic.transferHolder(
70
+ holderAddress
71
+ );
72
+ }
73
+ } catch (e) {
74
+ console.error("callStatic failed:", e);
75
+ throw new Error("Pre-check (callStatic) for transferHolder failed");
76
+ }
77
+ if (!maxFeePerGas || !maxPriorityFeePerGas) {
78
+ chainId = chainId ?? await getChainIdSafe(signer);
79
+ const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
80
+ if (gasStation) {
81
+ const gasFees = await gasStation();
82
+ maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
83
+ maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
84
+ }
85
+ }
86
+ const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
87
+ if (isV5TT) {
88
+ return await titleEscrowContract.transferHolder(
89
+ holderAddress,
90
+ encryptedRemarks,
91
+ txOptions
92
+ );
93
+ } else if (isV4TT) {
94
+ return await titleEscrowContract.transferHolder(holderAddress, txOptions);
95
+ }
96
+ }, "transferHolder");
97
+ const transferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
98
+ const { tokenId, tokenRegistryAddress } = contractOptions;
99
+ const { titleEscrowVersion } = options;
100
+ let { titleEscrowAddress } = contractOptions;
101
+ let { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
102
+ let isV5TT = titleEscrowVersion === "v5";
103
+ let isV4TT = titleEscrowVersion === "v4";
104
+ if (!titleEscrowAddress) {
105
+ titleEscrowAddress = await core.getTitleEscrowAddress(
106
+ tokenRegistryAddress,
107
+ tokenId,
108
+ signer.provider,
109
+ { titleEscrowVersion }
110
+ );
111
+ }
112
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
113
+ if (!signer.provider) throw new Error("Provider is required");
114
+ const { newBeneficiaryAddress, remarks } = params;
115
+ let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
116
+ const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
117
+ if (titleEscrowVersion === void 0) {
118
+ [isV4TT, isV5TT] = await Promise.all([
119
+ core.isTitleEscrowVersion({
120
+ titleEscrowAddress,
121
+ versionInterface: core.TitleEscrowInterface.V4,
122
+ provider: signer.provider
123
+ }),
124
+ core.isTitleEscrowVersion({
125
+ titleEscrowAddress,
126
+ versionInterface: core.TitleEscrowInterface.V5,
127
+ provider: signer.provider
128
+ })
129
+ ]);
130
+ }
131
+ if (!isV4TT && !isV5TT) {
132
+ throw new Error("Only Token Registry V4/V5 is supported");
133
+ }
134
+ if (!isV5TT) {
135
+ titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
136
+ titleEscrowAddress,
137
+ signer
138
+ );
139
+ }
140
+ try {
141
+ if (isV5TT) {
142
+ await titleEscrowContract.callStatic.transferBeneficiary(
143
+ newBeneficiaryAddress,
144
+ encryptedRemarks
145
+ );
146
+ } else if (isV4TT) {
147
+ await titleEscrowContract.callStatic.transferBeneficiary(
148
+ newBeneficiaryAddress
149
+ );
150
+ }
151
+ } catch (e) {
152
+ console.error("callStatic failed:", e);
153
+ throw new Error("Pre-check (callStatic) for transferBeneficiary failed");
154
+ }
155
+ if (!maxFeePerGas || !maxPriorityFeePerGas) {
156
+ chainId = chainId ?? await getChainIdSafe(signer);
157
+ const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
158
+ if (gasStation) {
159
+ const gasFees = await gasStation();
160
+ maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
161
+ maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
162
+ }
163
+ }
164
+ const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
165
+ if (isV5TT) {
166
+ const tx = await titleEscrowContract.transferBeneficiary(
167
+ newBeneficiaryAddress,
168
+ encryptedRemarks,
169
+ txOptions
170
+ );
171
+ return tx;
172
+ } else if (isV4TT) {
173
+ const tx = await titleEscrowContract.transferBeneficiary(
174
+ newBeneficiaryAddress,
175
+ txOptions
176
+ );
177
+ return tx;
178
+ }
179
+ }, "transferBeneficiary");
180
+ const transferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
181
+ const { tokenId, tokenRegistryAddress } = contractOptions;
182
+ const { titleEscrowVersion } = options;
183
+ let { titleEscrowAddress } = contractOptions;
184
+ let { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
185
+ let isV5TT = titleEscrowVersion === "v5";
186
+ let isV4TT = titleEscrowVersion === "v4";
187
+ if (!titleEscrowAddress) {
188
+ titleEscrowAddress = await core.getTitleEscrowAddress(
189
+ tokenRegistryAddress,
190
+ tokenId,
191
+ signer.provider,
192
+ { titleEscrowVersion }
193
+ );
194
+ }
195
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
196
+ if (!signer.provider) throw new Error("Provider is required");
197
+ const { newBeneficiaryAddress, newHolderAddress, remarks } = params;
198
+ let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
199
+ const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
200
+ if (titleEscrowVersion === void 0) {
201
+ [isV4TT, isV5TT] = await Promise.all([
202
+ core.isTitleEscrowVersion({
203
+ titleEscrowAddress,
204
+ versionInterface: core.TitleEscrowInterface.V4,
205
+ provider: signer.provider
206
+ }),
207
+ core.isTitleEscrowVersion({
208
+ titleEscrowAddress,
209
+ versionInterface: core.TitleEscrowInterface.V5,
210
+ provider: signer.provider
211
+ })
212
+ ]);
213
+ }
214
+ if (!isV4TT && !isV5TT) {
215
+ throw new Error("Only Token Registry V4/V5 is supported");
216
+ }
217
+ if (!isV5TT) {
218
+ titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
219
+ titleEscrowAddress,
220
+ signer
221
+ );
222
+ }
223
+ try {
224
+ if (isV5TT) {
225
+ await titleEscrowContract.callStatic.transferOwners(
226
+ newBeneficiaryAddress,
227
+ newHolderAddress,
228
+ encryptedRemarks
229
+ );
230
+ } else if (isV4TT) {
231
+ await titleEscrowContract.callStatic.transferOwners(
232
+ newBeneficiaryAddress,
233
+ newHolderAddress
234
+ );
235
+ }
236
+ } catch (e) {
237
+ console.error("callStatic failed:", e);
238
+ throw new Error("Pre-check (callStatic) for transferOwners failed");
239
+ }
240
+ if (!maxFeePerGas || !maxPriorityFeePerGas) {
241
+ chainId = chainId ?? await getChainIdSafe(signer);
242
+ const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
243
+ if (gasStation) {
244
+ const gasFees = await gasStation();
245
+ maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
246
+ maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
247
+ }
248
+ }
249
+ const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
250
+ if (isV5TT) {
251
+ return await titleEscrowContract.transferOwners(
252
+ newBeneficiaryAddress,
253
+ newHolderAddress,
254
+ encryptedRemarks,
255
+ txOptions
256
+ );
257
+ } else if (isV4TT) {
258
+ return await titleEscrowContract.transferOwners(
259
+ newBeneficiaryAddress,
260
+ newHolderAddress,
261
+ txOptions
262
+ );
263
+ }
264
+ }, "transferOwners");
265
+ const nominate = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
266
+ const { tokenId, tokenRegistryAddress } = contractOptions;
267
+ const { titleEscrowVersion } = options;
268
+ let { titleEscrowAddress } = contractOptions;
269
+ let { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
270
+ let isV5TT = titleEscrowVersion === "v5";
271
+ let isV4TT = titleEscrowVersion === "v4";
272
+ if (!titleEscrowAddress) {
273
+ titleEscrowAddress = await core.getTitleEscrowAddress(
274
+ tokenRegistryAddress,
275
+ tokenId,
276
+ signer.provider,
277
+ { titleEscrowVersion }
278
+ );
279
+ }
280
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
281
+ if (!signer.provider) throw new Error("Provider is required");
282
+ const { newBeneficiaryAddress, remarks } = params;
283
+ let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
284
+ const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
285
+ if (titleEscrowVersion === void 0) {
286
+ [isV4TT, isV5TT] = await Promise.all([
287
+ core.isTitleEscrowVersion({
288
+ titleEscrowAddress,
289
+ versionInterface: core.TitleEscrowInterface.V4,
290
+ provider: signer.provider
291
+ }),
292
+ core.isTitleEscrowVersion({
293
+ titleEscrowAddress,
294
+ versionInterface: core.TitleEscrowInterface.V5,
295
+ provider: signer.provider
296
+ })
297
+ ]);
298
+ }
299
+ if (!isV5TT) {
300
+ titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
301
+ titleEscrowAddress,
302
+ signer
303
+ );
304
+ }
305
+ try {
306
+ if (isV5TT) {
307
+ await titleEscrowContract.callStatic.nominate(
308
+ newBeneficiaryAddress,
309
+ encryptedRemarks
310
+ );
311
+ } else if (isV4TT) {
312
+ await titleEscrowContract.callStatic.nominate(
313
+ newBeneficiaryAddress
314
+ );
315
+ }
316
+ } catch (e) {
317
+ console.error("callStatic failed:", e);
318
+ throw new Error("Pre-check (callStatic) for nominate failed");
319
+ }
320
+ if (!maxFeePerGas || !maxPriorityFeePerGas) {
321
+ chainId = chainId ?? await getChainIdSafe(signer);
322
+ const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
323
+ if (gasStation) {
324
+ const gasFees = await gasStation();
325
+ maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
326
+ maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
327
+ }
328
+ }
329
+ const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
330
+ if (isV5TT) {
331
+ return await titleEscrowContract.nominate(
332
+ newBeneficiaryAddress,
333
+ encryptedRemarks,
334
+ txOptions
335
+ );
336
+ } else if (isV4TT) {
337
+ return await titleEscrowContract.nominate(
338
+ newBeneficiaryAddress,
339
+ txOptions
340
+ );
341
+ }
342
+ }, "nominate");
343
+
344
+ exports.nominate = nominate;
345
+ exports.transferBeneficiary = transferBeneficiary;
346
+ exports.transferHolder = transferHolder;
347
+ exports.transferOwners = transferOwners;
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 @@
1
+ export * from './transfer';
@@ -0,0 +1,342 @@
1
+ import { SUPPORTED_CHAINS } from '@tradetrust-tt/tradetrust-utils';
2
+ import { getTitleEscrowAddress, encrypt, isTitleEscrowVersion, TitleEscrowInterface } from 'src/core';
3
+ import { v4Contracts } from 'src/token-registry-v4';
4
+ import { v5Contracts } from 'src/token-registry-v5';
5
+ import { isV6EthersProvider } from 'src/utils/ethers';
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ const getChainIdSafe = /* @__PURE__ */ __name(async (signer) => {
10
+ if (isV6EthersProvider(signer.provider)) {
11
+ const network = await signer.provider?.getNetwork();
12
+ if (!network?.chainId) throw new Error("Cannot determine chainId: provider is missing");
13
+ return network.chainId;
14
+ }
15
+ return await signer.getChainId();
16
+ }, "getChainIdSafe");
17
+ const transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
18
+ const { tokenRegistryAddress, tokenId } = contractOptions;
19
+ const { titleEscrowVersion } = options;
20
+ let { titleEscrowAddress } = contractOptions;
21
+ let { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
22
+ let isV5TT = titleEscrowVersion === "v5";
23
+ let isV4TT = titleEscrowVersion === "v4";
24
+ if (!titleEscrowAddress) {
25
+ titleEscrowAddress = await getTitleEscrowAddress(
26
+ tokenRegistryAddress,
27
+ tokenId,
28
+ signer.provider,
29
+ { titleEscrowVersion }
30
+ );
31
+ }
32
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
33
+ if (!signer.provider) throw new Error("Provider is required");
34
+ const { holderAddress, remarks } = params;
35
+ let titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
36
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
37
+ if (titleEscrowVersion === void 0) {
38
+ [isV4TT, isV5TT] = await Promise.all([
39
+ isTitleEscrowVersion({
40
+ titleEscrowAddress,
41
+ versionInterface: TitleEscrowInterface.V4,
42
+ provider: signer.provider
43
+ }),
44
+ isTitleEscrowVersion({
45
+ titleEscrowAddress,
46
+ versionInterface: TitleEscrowInterface.V5,
47
+ provider: signer.provider
48
+ })
49
+ ]);
50
+ }
51
+ if (!isV4TT && !isV5TT) {
52
+ throw new Error("Only Token Registry V4/V5 is supported");
53
+ }
54
+ if (isV4TT) {
55
+ titleEscrowContract = v4Contracts.TitleEscrow__factory.connect(
56
+ titleEscrowAddress,
57
+ signer
58
+ );
59
+ }
60
+ try {
61
+ if (isV5TT) {
62
+ await titleEscrowContract.callStatic.transferHolder(
63
+ holderAddress,
64
+ encryptedRemarks
65
+ );
66
+ } else if (isV4TT) {
67
+ await titleEscrowContract.callStatic.transferHolder(
68
+ holderAddress
69
+ );
70
+ }
71
+ } catch (e) {
72
+ console.error("callStatic failed:", e);
73
+ throw new Error("Pre-check (callStatic) for transferHolder failed");
74
+ }
75
+ if (!maxFeePerGas || !maxPriorityFeePerGas) {
76
+ chainId = chainId ?? await getChainIdSafe(signer);
77
+ const gasStation = SUPPORTED_CHAINS[chainId]?.gasStation;
78
+ if (gasStation) {
79
+ const gasFees = await gasStation();
80
+ maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
81
+ maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
82
+ }
83
+ }
84
+ const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
85
+ if (isV5TT) {
86
+ return await titleEscrowContract.transferHolder(
87
+ holderAddress,
88
+ encryptedRemarks,
89
+ txOptions
90
+ );
91
+ } else if (isV4TT) {
92
+ return await titleEscrowContract.transferHolder(holderAddress, txOptions);
93
+ }
94
+ }, "transferHolder");
95
+ const transferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
96
+ const { tokenId, tokenRegistryAddress } = contractOptions;
97
+ const { titleEscrowVersion } = options;
98
+ let { titleEscrowAddress } = contractOptions;
99
+ let { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
100
+ let isV5TT = titleEscrowVersion === "v5";
101
+ let isV4TT = titleEscrowVersion === "v4";
102
+ if (!titleEscrowAddress) {
103
+ titleEscrowAddress = await getTitleEscrowAddress(
104
+ tokenRegistryAddress,
105
+ tokenId,
106
+ signer.provider,
107
+ { titleEscrowVersion }
108
+ );
109
+ }
110
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
111
+ if (!signer.provider) throw new Error("Provider is required");
112
+ const { newBeneficiaryAddress, remarks } = params;
113
+ let titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
114
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
115
+ if (titleEscrowVersion === void 0) {
116
+ [isV4TT, isV5TT] = await Promise.all([
117
+ isTitleEscrowVersion({
118
+ titleEscrowAddress,
119
+ versionInterface: TitleEscrowInterface.V4,
120
+ provider: signer.provider
121
+ }),
122
+ isTitleEscrowVersion({
123
+ titleEscrowAddress,
124
+ versionInterface: TitleEscrowInterface.V5,
125
+ provider: signer.provider
126
+ })
127
+ ]);
128
+ }
129
+ if (!isV4TT && !isV5TT) {
130
+ throw new Error("Only Token Registry V4/V5 is supported");
131
+ }
132
+ if (!isV5TT) {
133
+ titleEscrowContract = v4Contracts.TitleEscrow__factory.connect(
134
+ titleEscrowAddress,
135
+ signer
136
+ );
137
+ }
138
+ try {
139
+ if (isV5TT) {
140
+ await titleEscrowContract.callStatic.transferBeneficiary(
141
+ newBeneficiaryAddress,
142
+ encryptedRemarks
143
+ );
144
+ } else if (isV4TT) {
145
+ await titleEscrowContract.callStatic.transferBeneficiary(
146
+ newBeneficiaryAddress
147
+ );
148
+ }
149
+ } catch (e) {
150
+ console.error("callStatic failed:", e);
151
+ throw new Error("Pre-check (callStatic) for transferBeneficiary failed");
152
+ }
153
+ if (!maxFeePerGas || !maxPriorityFeePerGas) {
154
+ chainId = chainId ?? await getChainIdSafe(signer);
155
+ const gasStation = SUPPORTED_CHAINS[chainId]?.gasStation;
156
+ if (gasStation) {
157
+ const gasFees = await gasStation();
158
+ maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
159
+ maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
160
+ }
161
+ }
162
+ const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
163
+ if (isV5TT) {
164
+ const tx = await titleEscrowContract.transferBeneficiary(
165
+ newBeneficiaryAddress,
166
+ encryptedRemarks,
167
+ txOptions
168
+ );
169
+ return tx;
170
+ } else if (isV4TT) {
171
+ const tx = await titleEscrowContract.transferBeneficiary(
172
+ newBeneficiaryAddress,
173
+ txOptions
174
+ );
175
+ return tx;
176
+ }
177
+ }, "transferBeneficiary");
178
+ const transferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
179
+ const { tokenId, tokenRegistryAddress } = contractOptions;
180
+ const { titleEscrowVersion } = options;
181
+ let { titleEscrowAddress } = contractOptions;
182
+ let { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
183
+ let isV5TT = titleEscrowVersion === "v5";
184
+ let isV4TT = titleEscrowVersion === "v4";
185
+ if (!titleEscrowAddress) {
186
+ titleEscrowAddress = await getTitleEscrowAddress(
187
+ tokenRegistryAddress,
188
+ tokenId,
189
+ signer.provider,
190
+ { titleEscrowVersion }
191
+ );
192
+ }
193
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
194
+ if (!signer.provider) throw new Error("Provider is required");
195
+ const { newBeneficiaryAddress, newHolderAddress, remarks } = params;
196
+ let titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
197
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
198
+ if (titleEscrowVersion === void 0) {
199
+ [isV4TT, isV5TT] = await Promise.all([
200
+ isTitleEscrowVersion({
201
+ titleEscrowAddress,
202
+ versionInterface: TitleEscrowInterface.V4,
203
+ provider: signer.provider
204
+ }),
205
+ isTitleEscrowVersion({
206
+ titleEscrowAddress,
207
+ versionInterface: TitleEscrowInterface.V5,
208
+ provider: signer.provider
209
+ })
210
+ ]);
211
+ }
212
+ if (!isV4TT && !isV5TT) {
213
+ throw new Error("Only Token Registry V4/V5 is supported");
214
+ }
215
+ if (!isV5TT) {
216
+ titleEscrowContract = v4Contracts.TitleEscrow__factory.connect(
217
+ titleEscrowAddress,
218
+ signer
219
+ );
220
+ }
221
+ try {
222
+ if (isV5TT) {
223
+ await titleEscrowContract.callStatic.transferOwners(
224
+ newBeneficiaryAddress,
225
+ newHolderAddress,
226
+ encryptedRemarks
227
+ );
228
+ } else if (isV4TT) {
229
+ await titleEscrowContract.callStatic.transferOwners(
230
+ newBeneficiaryAddress,
231
+ newHolderAddress
232
+ );
233
+ }
234
+ } catch (e) {
235
+ console.error("callStatic failed:", e);
236
+ throw new Error("Pre-check (callStatic) for transferOwners failed");
237
+ }
238
+ if (!maxFeePerGas || !maxPriorityFeePerGas) {
239
+ chainId = chainId ?? await getChainIdSafe(signer);
240
+ const gasStation = SUPPORTED_CHAINS[chainId]?.gasStation;
241
+ if (gasStation) {
242
+ const gasFees = await gasStation();
243
+ maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
244
+ maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
245
+ }
246
+ }
247
+ const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
248
+ if (isV5TT) {
249
+ return await titleEscrowContract.transferOwners(
250
+ newBeneficiaryAddress,
251
+ newHolderAddress,
252
+ encryptedRemarks,
253
+ txOptions
254
+ );
255
+ } else if (isV4TT) {
256
+ return await titleEscrowContract.transferOwners(
257
+ newBeneficiaryAddress,
258
+ newHolderAddress,
259
+ txOptions
260
+ );
261
+ }
262
+ }, "transferOwners");
263
+ const nominate = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
264
+ const { tokenId, tokenRegistryAddress } = contractOptions;
265
+ const { titleEscrowVersion } = options;
266
+ let { titleEscrowAddress } = contractOptions;
267
+ let { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
268
+ let isV5TT = titleEscrowVersion === "v5";
269
+ let isV4TT = titleEscrowVersion === "v4";
270
+ if (!titleEscrowAddress) {
271
+ titleEscrowAddress = await getTitleEscrowAddress(
272
+ tokenRegistryAddress,
273
+ tokenId,
274
+ signer.provider,
275
+ { titleEscrowVersion }
276
+ );
277
+ }
278
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
279
+ if (!signer.provider) throw new Error("Provider is required");
280
+ const { newBeneficiaryAddress, remarks } = params;
281
+ let titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
282
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
283
+ if (titleEscrowVersion === void 0) {
284
+ [isV4TT, isV5TT] = await Promise.all([
285
+ isTitleEscrowVersion({
286
+ titleEscrowAddress,
287
+ versionInterface: TitleEscrowInterface.V4,
288
+ provider: signer.provider
289
+ }),
290
+ isTitleEscrowVersion({
291
+ titleEscrowAddress,
292
+ versionInterface: TitleEscrowInterface.V5,
293
+ provider: signer.provider
294
+ })
295
+ ]);
296
+ }
297
+ if (!isV5TT) {
298
+ titleEscrowContract = v4Contracts.TitleEscrow__factory.connect(
299
+ titleEscrowAddress,
300
+ signer
301
+ );
302
+ }
303
+ try {
304
+ if (isV5TT) {
305
+ await titleEscrowContract.callStatic.nominate(
306
+ newBeneficiaryAddress,
307
+ encryptedRemarks
308
+ );
309
+ } else if (isV4TT) {
310
+ await titleEscrowContract.callStatic.nominate(
311
+ newBeneficiaryAddress
312
+ );
313
+ }
314
+ } catch (e) {
315
+ console.error("callStatic failed:", e);
316
+ throw new Error("Pre-check (callStatic) for nominate failed");
317
+ }
318
+ if (!maxFeePerGas || !maxPriorityFeePerGas) {
319
+ chainId = chainId ?? await getChainIdSafe(signer);
320
+ const gasStation = SUPPORTED_CHAINS[chainId]?.gasStation;
321
+ if (gasStation) {
322
+ const gasFees = await gasStation();
323
+ maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
324
+ maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
325
+ }
326
+ }
327
+ const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
328
+ if (isV5TT) {
329
+ return await titleEscrowContract.nominate(
330
+ newBeneficiaryAddress,
331
+ encryptedRemarks,
332
+ txOptions
333
+ );
334
+ } else if (isV4TT) {
335
+ return await titleEscrowContract.nominate(
336
+ newBeneficiaryAddress,
337
+ txOptions
338
+ );
339
+ }
340
+ }, "nominate");
341
+
342
+ export { nominate, transferBeneficiary, transferHolder, transferOwners };
@@ -10,6 +10,7 @@ export { supportInterfaceIds as v5SupportInterfaceIds } from './token-registry-v
10
10
  export { c as v5Contracts } from './contracts-BaIGKzNt.js';
11
11
  export { computeInterfaceId as v5ComputeInterfaceId, encodeInitParams as v5EncodeInitParams, getEventFromReceipt as v5GetEventFromReceipt } from './token-registry-v5/utils.js';
12
12
  export { TypedContractMethod } from '@tradetrust-tt/token-registry-v5/contracts/common';
13
+ export { nominate, transferBeneficiary, transferHolder, transferOwners } from './token-registry-functions/transfer.js';
13
14
  export { decrypt } from './core/decrypt.js';
14
15
  export { encrypt } from './core/encrypt.js';
15
16
  export { verifyDocument } from './core/verify.js';
@@ -0,0 +1,4 @@
1
+ export { nominate, transferBeneficiary, transferHolder, transferOwners } from './transfer.js';
2
+ import '@tradetrust-tt/tradetrust-utils';
3
+ import 'ethersV6';
4
+ import 'ethers';
@@ -0,0 +1,43 @@
1
+ import { CHAIN_ID } from '@tradetrust-tt/tradetrust-utils';
2
+ import { Signer as Signer$1, BigNumberish } from 'ethersV6';
3
+ import { Signer, BigNumber } from 'ethers';
4
+
5
+ interface TransferHolderParams {
6
+ holderAddress: string;
7
+ remarks?: string;
8
+ }
9
+ interface TransferBeneficiaryParams {
10
+ newBeneficiaryAddress: string;
11
+ remarks?: string;
12
+ }
13
+ interface NominateParams {
14
+ newBeneficiaryAddress: string;
15
+ remarks?: string;
16
+ }
17
+ interface TransferOwnersParams {
18
+ newHolderAddress: string;
19
+ newBeneficiaryAddress: string;
20
+ remarks?: string;
21
+ }
22
+ interface TransferOptions {
23
+ chainId?: CHAIN_ID;
24
+ titleEscrowVersion?: 'v4' | 'v5';
25
+ maxFeePerGas?: BigNumberish | string | number | BigNumber;
26
+ maxPriorityFeePerGas?: BigNumberish | string | number | BigNumber;
27
+ id?: string;
28
+ }
29
+ type ContractOptions = {
30
+ titleEscrowAddress: string;
31
+ tokenId?: string | number;
32
+ tokenRegistryAddress?: string;
33
+ } | {
34
+ titleEscrowAddress?: undefined;
35
+ tokenId: string | number;
36
+ tokenRegistryAddress: string;
37
+ };
38
+ declare const transferHolder: (contractOptions: ContractOptions, signer: Signer | Signer$1, params: TransferHolderParams, options: TransferOptions) => Promise<ContractTransactionResponse>;
39
+ declare const transferBeneficiary: (contractOptions: ContractOptions, signer: Signer | Signer$1, params: TransferBeneficiaryParams, options: TransferOptions) => Promise<any>;
40
+ declare const transferOwners: (contractOptions: ContractOptions, signer: Signer | Signer$1, params: TransferOwnersParams, options: TransferOptions) => Promise<any>;
41
+ declare const nominate: (contractOptions: ContractOptions, signer: Signer | Signer$1, params: NominateParams, options: TransferOptions) => Promise<any>;
42
+
43
+ export { nominate, transferBeneficiary, transferHolder, transferOwners };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustvc/trustvc",
3
- "version": "1.5.4",
3
+ "version": "1.6.0-alpha.1",
4
4
  "description": "TrustVC library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -111,18 +111,18 @@
111
111
  },
112
112
  "dependencies": {
113
113
  "@tradetrust-tt/dnsprove": "^2.17.0",
114
- "@tradetrust-tt/ethers-aws-kms-signer": "^2.1.3",
114
+ "@tradetrust-tt/ethers-aws-kms-signer": "^2.1.4",
115
115
  "@tradetrust-tt/token-registry-v4": "npm:@tradetrust-tt/token-registry@^4.16.0",
116
116
  "@tradetrust-tt/token-registry-v5": "npm:@tradetrust-tt/token-registry@^5.3.0",
117
117
  "@tradetrust-tt/tradetrust": "^6.10.1",
118
118
  "@tradetrust-tt/tradetrust-utils": "^2.3.2",
119
119
  "@tradetrust-tt/tt-verify": "^9.4.0",
120
120
  "@trustvc/w3c-context": "^1.2.13",
121
- "@trustvc/w3c-credential-status": "^1.2.12",
122
- "@trustvc/w3c-issuer": "^1.2.3",
121
+ "@trustvc/w3c-credential-status": "^1.2.13",
122
+ "@trustvc/w3c-issuer": "^1.2.4",
123
123
  "@trustvc/w3c-vc": "^1.2.17",
124
124
  "ethers": "^5.8.0",
125
- "ethersV6": "npm:ethers@^6.14.3",
125
+ "ethersV6": "npm:ethers@^6.14.4",
126
126
  "js-sha3": "^0.9.3",
127
127
  "ts-chacha20": "^1.2.0"
128
128
  },